• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Calling script

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic