Forums Register Login

Reg:Executing Commands

+Pie Number of slices to send: Send
Hi,
I have developed an application in swings in which a user will schedule a command. So to make it user friendly the user will enter only the command, like the "del d:\exp.txt". I am successful in all other parts of the program but when i try to run the command from java i get the error. The code is below some one guide me through it please.


When i try to run the commands like the java or the task list i get the out put. But the command which i have written in the exec method gives error why so. the error is


java.io.IOException: Cannot run program "del": CreateProcess error=2, The system
cannot find the file specified
java.io.IOException: Cannot run program "del": CreateProcess error=2, The system
cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:431)
at java.lang.Runtime.exec(Runtime.java:328)
at comm.main(comm.java:12)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find th
e file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
at java.lang.ProcessImpl.start(ProcessImpl.java:30)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
... 4 more
Press any key to continue...



Thanks & Regards
alexander
+Pie Number of slices to send: Send
"del" is not an application, it's a built-in command of the "cmd.exe" application. Try "cmd /C del d:/exp.txt". There might be problems when the file has spaces in its absolute name though, but that's an issue with cmd.exe.
+Pie Number of slices to send: Send
Thanks for your reply Prime. I have done what you said but still i get the error. The error is.


Exited with error code 1


+Pie Number of slices to send: Send
Does the file exist? What happens if you call the command directly, without Java?
+Pie Number of slices to send: Send
Yes the file exist. The command works when i use it directly from command prompt.
when i use the command dir from java its working. But like del and copy are not Working.
+Pie Number of slices to send: Send
Its giving exited with error code 0, when i run the code below. But the file is not deleted.
+Pie Number of slices to send: Send
Your code works just fine on my PC.
grapes are vegan food pellets. Eat this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 8220 times.
Similar Threads
Runtime getRuntime() exec(String command) - How does this work?
using windows command line to copy and paste. getting file not found error
how to open the excel file in java program?
Reading nconvert.exe in java???????????
Exception - Running command line from Java
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 22:43:26.