Runtime r= Runtime.getRuntime();
r.exec("copy copy c:\autoexec.bat c:\autoexec.old");
The error message that I get is as follows:
java.io.IOException: CreateProcess: copy c:\autoexec.bat c:\autoexec.old
error=2
at java.lang.Win32Process.<init>(Win32Process.java:59)
at java.lang.Runtime.exec(Runtime.java:175)
at java.lang.Runtime.exec(Runtime.java:137)
However, if I try to run a windows program the same way as follows then the
code works... :
Runtime r= Runtime.getRuntime();
r.exec("notepad.exe");
does anyone have any suggestions or solutions?
Regards,
Aaron.
Paul
The problem is, that `copy´ is a builtin-command of cmd.exe
resp. command.com. So you have to call one of these shells with the
option /c :
Process p = Runtime.getRuntime().
exec("cmd /c \"copy c:\\autoexec.bat c:\\autoexec.old\"");
Also don't forget to escape the chars " and \ .
Thorsten Seelend
Do you have a program named "COPY." on your system? I thought not. There is
a program called "COMMAND.COM" on win32 systems, and it has an internal
subcommand named "COPY". Perhaps that is what you meant to run. This has
nothing to do with Java, BTW. You would get the same error from a C program
(but no stack trace :-).
From memory, the /C option to COMMAND.COM lets you run internal commands from
the command line:
r.exec("COMMAND.COM /C copy c:\\autoexec.bat c:\\autoexec.old");
--
Stuart D. Gathman <stu...@bmsi.com>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"Microsoft is the QWERTY of Operating Systems" - SDG
"Confutatis maledictus, flamis acribus addictus" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.
(HINT: Find translation for the "Confutatis" movement of the Mozart Requiem).