0

My command is:

Runtime.getRuntime().exec("cmd /c copy /b D:\\MeAgent\\Reports\\receipt.hex lpt2:");
System.out.println("test");

In the console comes the "test", but the command is not executed and it comes no errormessage :(

FabianG
  • 120
  • 1
  • 2
  • 10

1 Answers1

2

Looks like you don't escape the last backslash.

Edit - now you've fixed the obvious

When you call exec you spawn a Process. You need to wait for that process to finish.

What you've got here is a race condition - i.e. your code is completing before the process executes.

http://docs.oracle.com/javase/1.7/docs/api/java/lang/Process.html

Dan
  • 1,030
  • 5
  • 12
  • I did it, I wrote it only false here :( – FabianG Aug 21 '12 at 08:58
  • It dosent work :( I have tried it with a "while loop", with "wait" and try { Process p = null; p = Runtime.getRuntime().exec("cmd.exe"); p.waitFor(); } catch (InterruptedException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } – FabianG Aug 21 '12 at 09:14
  • Can you use a javadoc link from Java 7? – Peter Lawrey Aug 21 '12 at 10:04