Results 1 to 12 of 12
Thread: Problem with Runtime.exec()
- 07-01-2008, 06:52 AM #1
Member
- Join Date
- Jul 2008
- Posts
- 5
- Rep Power
- 0
Problem with Runtime.exec()
Hi all,
I want to get a list of a directory with dir command (windows Vista). I write:
Runtime.getRuntime.exec("cmd.exe /C dir " + MyPath);
but the command can't find the specified path for dir. My question is that how we can pass an argument for command line's programs like dir, copy,etc?
:confused:
- 07-01-2008, 06:56 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Should be
Java Code:getRuntime()
- 07-01-2008, 07:30 AM #3
Member
- Join Date
- Jul 2008
- Posts
- 5
- Rep Power
- 0
Yes, actually it is:
Runtime.getRuntime().exec().
I made a mistake in posting.
What is the problem?
- 07-01-2008, 08:53 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 8
Why don't you just use File?
But, did you use the full path? Or did you use a partial path, in which case, your "current path" is probably not what you thought it was.
- 07-01-2008, 09:03 AM #5
Member
- Join Date
- Jul 2008
- Posts
- 5
- Rep Power
- 0
I ue the full path. I know that I can do it with File, but I want to know how to do with exec().
- 07-01-2008, 09:05 AM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 8
Well, it might help to show the actual code, but probably better is this:
When Runtime.exec() won't - Java World
- 07-01-2008, 09:16 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Did you get any Exceptions here?
- 07-01-2008, 10:02 AM #8
Member
- Join Date
- Jul 2008
- Posts
- 5
- Rep Power
- 0
no exception
- 07-01-2008, 10:22 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Did you check the output is correct, trying to write into a stream? And also the best way is, use a command string array. Check overloaded functions of exec().
- 07-01-2008, 04:25 PM #10
What happens if you leave off the cmd.exe /C and start the comand with dir?
Have you tried the exec() with other commands and gotten them to work?
- 07-01-2008, 06:06 PM #11
Member
- Join Date
- Jul 2008
- Posts
- 5
- Rep Power
- 0
It solved. If a program generates output or error, you should get the stream and write it immediately.
I read the javaworld article, thanks Masijade :)
- 07-02-2008, 01:35 AM #12
Member
- Join Date
- Jun 2008
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
Runtime.exec(), handling input and output streams
By crookshank in forum New To JavaReplies: 0Last Post: 06-05-2008, 02:41 PM -
Example of RunTime class
By Java Tip in forum Java TipReplies: 0Last Post: 01-04-2008, 09:32 AM -
Exec cmd from Java application
By javaplus in forum New To JavaReplies: 0Last Post: 12-17-2007, 08:41 AM -
runtime method
By roo7 in forum Advanced JavaReplies: 5Last Post: 11-30-2007, 04:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks