running external programs


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: running external programs

  1. #1
    Join Date
    Feb 2005
    Posts
    2

    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.

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    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

  3. #3
    Join Date
    Feb 2005
    Posts
    2

    thank you

    thank you.i'll try that.

  4. #4
    Join Date
    Jan 2005
    Posts
    15
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center