Results 1 to 3 of 3
- 06-09-2010, 11:45 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 4
- Rep Power
- 0
read commands from file and run it
Hi!
How can I read a text file with differents commands like ps aux, ls -al, etc. and run it?
I using fileinputstream and runtime.
I just need some help to find some examples to do that.
This work->
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("c:\\test.exe -id=jallaf -password=jallaf run test");
I want it to be like this:
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(file-with-command.txt + "-id=jallaf -password=jallaf run test");
hope you understanding my problem.
Thanks
- 06-09-2010, 01:15 PM #2
Member
- Join Date
- May 2010
- Posts
- 2
- Rep Power
- 0
Assuming you are working on unix platform, you need to run it as script(shell or perl). Just put all your commands in a file say "commands.sh".
Assign execute permission using chmod:-
chmod 777 commands.sh
Then, in Java do like this:-
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(relative-or-complete-path -of-file(commands.sh) + "-id=jallaf -password=jallaf run test");
- 06-09-2010, 02:36 PM #3
Member
- Join Date
- Jun 2010
- Posts
- 4
- Rep Power
- 0
thank you very much. it's work.
But I have another runtime issue too.
I want the java application read the string into a file.txt and put it in a runtime command.
The issue is: I have a windows application in wine. The text file is for example
cat file.txt
c:\\program files\\shure\\shure.exe
The java application should read this line and put it into here -->
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(c:\\program files\\shure\\shure.exe "any-command-for-shure");
("any-command-for-shure") is always in the java application - but the string in the text file will change. maybe somebody want to install shure in c:\shure\ so they have to write c:\\shure\\shure.exe in the text file.
I think I should use a FileInputStream and read the file. The string is like String name = "shure";
and i will put the variable in Process pr = rt.exec(shure + "any-command-for-shure"); ??
I hope you understand me this time too.
Thanks.Last edited by keneid; 06-09-2010 at 02:42 PM.
Similar Threads
-
Help file for Java commands?
By tyang in forum New To JavaReplies: 2Last Post: 01-31-2010, 05:09 AM -
Read file from directory, update contents of the each file
By svpriyan in forum New To JavaReplies: 2Last Post: 05-11-2009, 10:07 AM -
how to read openproj(Projity) file i.e. ,POD file(Project Management file)
By mahendra.athneria in forum New To JavaReplies: 0Last Post: 02-11-2009, 09:53 AM -
How to read and write to a file without taking out the comments in the file
By MAGNUM in forum New To JavaReplies: 5Last Post: 02-05-2009, 10:28 AM -
How to read a text file from a Java Archive File
By Java Tip in forum Java TipReplies: 0Last Post: 02-08-2008, 09:13 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks