*
The moose likes Beginning Java and the fly likes Calling script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calling script " Watch "Calling script " New topic
Author

Calling script

Bill Norton
Greenhorn

Joined: Mar 29, 2001
Posts: 27
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

Joined: Sep 29, 2000
Posts: 8521
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");


"JavaRanch, where the deer and the Certified play" - David O'Meara
Thomas Whalen
Ranch Hand

Joined: Aug 26, 2001
Posts: 123
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


if you don't know, then ask. if you do know, then share. love is knowledge.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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

Joined: Mar 16, 2001
Posts: 984

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).]


Please ignore post, I have no idea what I am talking about.
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

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).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling script
 
Similar Threads
getting and setting environment variables
Launch files from cmd line
Java ProcessBuilder ignoring flags
Super user on unix not honoured by Java?
what shell is this