Inputting a Console Command

How do I make a program that automatically inputs "java -jar <program.jar>" into the command prompt?
Er, how exactly do you wish to do this?
Are you planning to drag and drop jar files on to it?
Do you wish to just type "foo.jar" to execute foo.jar?
Do you wish to type "j foo" to execute foo.jar?

To answer your specific question, use system() or an OS-specific function. There might be a better way to do what you want, though.
I'd like a desktop icon that executes the foo for me, just with the parameter of "-jar" so I don't have to enter it manually each time.
Just run it with "javaw"
...or make a simple shell/batch, Perl, Python, ... (you get the idea) script. This problem is overkill for an executable program, but yea, you would do it with "system".
1
2
3
4
5
6
7
8
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
    string cmd = "java -jar ";
    cmd += static_cast<string>(argv[0]);
    system( cmd.c_str() );
    return 0;
}

Try that!
Topic archived. No new replies allowed.