Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to run unix pipe from mkisofs and cdrecord in windows with java

 
benny rusli
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello people,
I want to run the command(on the fly brennen command)
String[] cmd = {"c:\\mkisofs","-J","-R","c:\\javatutor","|","c:\\cdrecord","-v","-dev=1,0,0","speed=10","driveropts=burnfree","-tao","-data","-"};
from within java program, the error messages are, the pipe symbol | and minus - symbol are not recognising, has anybody tried this before, if yes then please let me know, it will be a great help. If i run only mkisofs or only cdrecord (mean separate), that will be successfully. I have already tried to run under dos command line all that command were successfully running.
public void runcmd()
{
java.lang.Runtime rt = java.lang.Runtime.getRuntime();
String[] cmd = {"c:\\mkisofs","-J","-R","c:\\javatutor","|","c:\\cdrecord","-v","-dev=1,0,0","speed=10","driveropts=burnfree","-tao","-data","-"};
try
{
java.lang.Process p = rt.exec(cmd);
java.io.InputStream is = p.getInputStream();
java.io.InputStreamReader isr = new java.io.InputStreamReader(is);
java.io.BufferedReader br = new java.io.BufferedReader(isr);
String count = "";
while((count=br.readLine()) != null)
{
System.out.println(count);
}
br.close();
try
{
if(p.waitFor() != 0)
{
System.err.println("Return value = "+p.exitValue());
}
}
catch(java.lang.InterruptedException ioe)
{
System.out.println(ioe);
}
}
catch(java.io.IOException ioe)
{
System.out.println(ioe);
}
}
 
Joseph Maddison
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you could write the command to a batch file/shell script and execute that file with Runtime.exec()?

HTH,
jdmaddison
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...or you catch the output of the first command yourself, and put it to a second command as input yourself.
The reason is, that the in- and outputstreams aren't available as normal, when you run from java. (">" "<" "|" ">>" "<<" - operators).
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"|" and "<" and ">", etc, are handled by the shell. When you Runtime.exec() a command, no shell is involved. To make this work, you have to invoke the shell, and tell it to run the pipeline; i.e.,



Now, this requires your having Cygwin installed to provide the shell, and I imagine it will take some fiddling to get it all going, but this is the general idea.
 
benny rusli
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I try to do what you say (Stefan Wagner)

"...or you catch the output of the first command yourself, and put it to a second command as input yourself.
The reason is, that the in- and outputstreams aren't available as normal, when you run from java. (">" "<" "|" ">>" "<<" - operators)"

but still i dont get the output, no error.

 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't like to use EFHs approach, I would take a serious look at the processes and Streams:

I understood:

So the output of mkisofs is the input for cdrecord, right?

Your inputstream 'is' is bound to the inputstream of the cdrecord-command, and then you try to read from that...?

I found it allways confusing myself, because from one perspective the stream is an inputstream, and from the other an outputstream, then it looks simple, then confusing again...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic