Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IOException: CreateProcess: cmd.exe /c copy /B...

Status
Not open for further replies.

lesneskp

Programmer
Jul 3, 2002
19
US
Advice grately appreciated:

I can't for the life of me figure out why this doesn't work. From the command line, this works:

copy /B test.txt \\Hq2oakps2\p4103hp5k

And consulting this thread:


I wrote this code:

Process printJobProcess = null;
String printCommand = "cmd.exe /c copy /B " + tempPCLFile.getPath() + " \\\\Hq2oakps2\\p4103hp5k";
printJobProcess = Runtime.getRuntime().exec(printCommand);
printJobProcess.waitFor();

Which attempts to create this command:

cmd.exe /c copy /B C:\WINDOWS\TEMP\invoice-CAET20601B12946.pcl \\Hq2oakps2\p4103hp5k

But results in this error (I am -shamefully- having to work in Win98 at current; could that be an issue?):

java.io.IOException: CreateProcess: cmd.exe /c copy /B C:\WINDOWS\TEMP\invoice-CAET20601B12946.pcl \\Hq2oakps2\p4103hp5k error=0
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Unknown Source)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at com.apl.ppdi.appl.form.InvoicePrinter.printPCL(InvoicePrinter.java:214)

Advice grately appreciated
 
better yet...
Code:
    String osName = System.getProperty(&quot;os.name&quot; );
    String[] cmd = new String[3];
    if( osName.equals( &quot;Windows NT&quot; ) )
    {
      cmd[0] = &quot;cmd.exe&quot; ;
    }
    else
    {
      cmd[0] = &quot;command.com&quot; ;
    }
    cmd[1] = &quot;/C&quot;;
    cmd[2] = (com);
    Runtime rt = Runtime.getRuntime();
    System.out.println(&quot;Running command: &quot;+com);
    Process proc = rt.exec(cmd);
 
Exactly. That was indeed the problem.
Thanks all!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top