-
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.
eschew obfuscation
-
-
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks