running external programs
hi? how do i repeatedly run an external file with arguments in a java program?
example, i have to run an exe file named visual which takes in 3 arguments: label, ski, labeloutput:
visual -din label -cout skin -dout labeloutput
i have to put this in a loop and change label and labeloutput for every loop. when i make it dis way:
Runtime rt = Runtime.getRuntime ();
Process proc = rt.exec ("visual -din" + label + ".dat -cout skin.cod -dout" + labeloutput);
it does not work anymore and the process ends even before it's finished.how do i solve this? thank you.
Does this exe accept multiple running intstances of itself?
If it does, try starting a new thread for each invokation
and launch the runtime in the thread.
If you dont want multiple innstances running, then do
a wait() for the process, this also in a thread, or else
your main program will hang while the visual executes.
Take extra care when specifying a command together with command line options within a single string, i.e.,
rt.exec ("visual -din" + label + ".dat -cout skin.cod -dout" + labeloutput);
You may run into problems if label and labeloutput contain spaces within.
It's better to use the exec(String cmdarray) version. I've learned this the hard way...
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center