Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling script

 
Bill Norton
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel like this a pretty dumb ?, but I am trying to call a script in Linux. Code looks like this:
class callscript {
public static void main(String args[]) throws Exception {
String item = "sh -c ./mescript";
Process proc = Runtime.getRuntime().exec(item);
int rc = proc.waitFor();
}
}
mescript is just supposed to do an 'ls -al'
It compiles and runs but no output.
I have tried to replace the String with 'sh -c ls' No luck.
Any ideas.
Thanks,
Bill Norton
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I don't know Unix much, but in windows you would start a .bat file using:
Runtime.getRuntime().exec("cmd /c start run.bat");

 
Thomas Whalen
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i know this is a little off-track, but could you point me to a link that explicitly describes how to make a batch file in Win98/NT ? i don't like having to do dig up my java files from the command line so that i can run them. thanx
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Open notepad and type your commands, and save it with a .bat extension.
Or if you are at the DOS prompt just type
>edit whatever.bat
type your commands and save.
Make sure that they land in the directory that you will invoke them from (or in the path of course).
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am also interested in how this would work. I searched around and found a couple of clues.
If your command has spaces in it you want to do some thing like this:

And also saw a couple of examples that looked like this.

I still have not figured out how to put it all together.

[This message has been edited by christopher foran (edited November 20, 2001).]
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is most likely really ugly code (hopefully someone will jump in and clean it up) but it works.
By works I mean that I get the results of an "ls -l" command at the command line I run the java program from.


[This message has been edited by christopher foran (edited November 21, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic