Timothy
Timothy

Reputation: 1

Sending commands to jar with c++

I ran a .jar file (in c++) like so:

#include <iostream>
#include <windows.h>

using namespace std;

int main ()
{
    system("java -jar filename.jar");
    return 0;
}

Note: This runs perfectly just the way I want it, but how to I send commands to the jar app with c++ code? I know I can't do system("MyJavaAppCommand"); since that would just be executed by the windows command and not my app's. Thanks in advance.

Upvotes: 0

Views: 270

Answers (3)

dziam
dziam

Reputation: 1


I think that you might find pipes usefull.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365780(v=vs.85).aspx

Upvotes: 0

Jacopofar
Jacopofar

Reputation: 3507

You can just add arguments after "filename.jar". These values will be seen by Java inside the argc[] array in the usual public static void main(String argc[]) method.

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533880

I would try using command line arguments like

system("java -jar filename.jar arg1 arg2 ... argN");

There arguments are passed to your main method in

public static void main(String... args)

or

public static void main(String[] args)

Too many references to include here

https://www.google.co.uk/search?q=jar+command+line+arguments

Upvotes: 3

Related Questions