|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

07-01-2008, 07:52 AM
|
|
Member
|
|
Join Date: Jul 2008
Posts: 5
|
|
|
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?

|
|

07-01-2008, 07:56 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,875
|
|
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

07-01-2008, 08:30 AM
|
|
Member
|
|
Join Date: Jul 2008
Posts: 5
|
|
|
Yes, actually it is:
Runtime.getRuntime().exec().
I made a mistake in posting.
What is the problem?
|
|

07-01-2008, 09:53 AM
|
|
Senior Member
|
|
Join Date: Jun 2008
Posts: 150
|
|
|
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, 10:03 AM
|
|
Member
|
|
Join Date: Jul 2008
Posts: 5
|
|
|
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, 10:16 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,875
|
|
|
Did you get any Exceptions here?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

07-01-2008, 11:02 AM
|
|
Member
|
|
Join Date: Jul 2008
Posts: 5
|
|
|
no exception
|
|

07-01-2008, 11:22 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,875
|
|
|
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().
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

07-01-2008, 05:25 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: SW MO, USA
Posts: 707
|
|
|
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, 07:06 PM
|
|
Member
|
|
Join Date: Jul 2008
Posts: 5
|
|
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, 02:35 AM
|
|
Member
|
|
Join Date: Jul 2008
Posts: 12
|
|
Originally Posted by nhabibi
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?

Might need to have something like this ("cmd.exe /C dir """ + MyPath + """") had a similar issue with vbscript today, damn """" and spaces. This may not be exact but might help with your problem.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|