• Post Reply Bookmark Topic Watch Topic
  • New Topic

Runtime.exec command showing invalid flag  RSS feed

 
Sumitsharma Sharma
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to execute javac command using Runtime.getRuntime().exec() command but it is showing invalid flag error.

The code is as follow:
Process p = Runtime.getRuntime().exec("javac \"D:\\File\\Test.java\" 2> \"D:\\File\\log.txt\"");

and after executing this line it says that invalid flag: 2>
 
Paul Clapham
Sheriff
Posts: 22829
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not how you do redirection with the Runtime.exec() method. Look at the documentation for the Runtime object to find the methods to connect redirected files or whatever to the object.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and welcome to the Ranch
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To expand on what Paul said, operators like <, >, |, && and || are not part of commands but are instead part of the shell (bash, cmd.exe, etc). None of these work directly in commands in Java; you will need to create workarounds for all of them, and some are easier than others.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!