• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

kickin off a script from java

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I created a simple server and client for a pure java program. I pass two string parameters to the server java code. I need to pass these two strings to a unix script for it to run another non-java program. How do you:
1) pass the string properly
2) activate the script
3) receive a easy 0 or 1 (int) from the script (for response back through the client to the calling program and out to the user on the screen.) Got the easy pass back to the screen done just stuck on the script side.
 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


After script is finished, process exit code is located in proc.exitCode() as well.
You better do call to waitFor() anyway, to reap the process even if you are sure it has been completed. I don't know will Java leave any zombies lying around, but this is a good style.

------------------
With best of best regards, Pawel S. Veselov ( aka Black Angel )
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pawel i tried the same thing of calling a batch file with parameters in DOS but it doesnt seem to be working .
Also pl. tell me how can I run a java file from within a java program
Pl. help me out
ThanX
/** bfile is the batch file of DOS and 123 is the parameter that is passed to the batch file**/
class ext
{
public static void main(String args[])throws Exception{
String arg[] = new String[2];
arg[0] = "bfile";
arg[1] = "123";
Process proc = Runtime.getRuntime().exec(arg);
int rc = proc.waitFor();
}
}

------------------
 
Pawel Veselov
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure how Java define current working directory.
Try to call the script with the full name. Also, you better set an extension for the script or Win can just do not understand how to run the file, since M$ also believes an extension.

What about java file - if you DO want to start separate JVM, just call java Class.class [args] and thats all.
 
Prashant Bopardikar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Pawel,
But the problem still persists.
I am able to call a exe file with the method you have specified(by giving the absolute path) but the batch file is not getting executed , also the parameters are not getting passed
Pl. help
Also,
""What about java file - if you DO want to start separate JVM, just call java Class.class [args] and thats all.""
I did not get what you meant to say by this.i want to know how to
kick off a new java program thro a java program
 
Prashant Bopardikar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Pawel,
But the problem still persists.
I am able to call a exe file with the method you have specified(by giving the absolute path) but the batch file is not getting executed , also the parameters are not getting passed
Pl. help
Also,
""What about java file - if you DO want to start separate JVM, just call java Class.class [args] and thats all.""
I did not get what you meant to say by this.i want to know how to
kick off a new java program thro a java program
 
Prashant Bopardikar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Pawel,
But the problem still persists.
I am able to call a exe file with the method you have specified(by giving the absolute path) but the batch file is not getting executed , also the parameters are not getting passed
Pl. help
Also,
""What about java file - if you DO want to start separate JVM, just call java Class.class [args] and thats all.""
I did not get what you meant to say by this.i want to know how to
kick off a new java program thro a java program
 
David Weise
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ran off for a quick trip before I could say thanks, this solutions does work on a NT. As for the notes about directories, I pass these to the script via parameters so that this is not a problem for the server code being run.
Dave

Originally posted by Pawel Veselov:
[B]

After script is finished, process exit code is located in proc.exitCode() as well.
You better do call to waitFor() anyway, to reap the process even if you are sure it has been completed. I don't know will Java leave any zombies lying around, but this is a good style.
[/B]


 
reply
    Bookmark Topic Watch Topic
  • New Topic