wood burning stoves 2.0*
The moose likes Java in General and the fly likes how to run unix pipe from mkisofs and cdrecord in windows with java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to run unix pipe from mkisofs and cdrecord in windows with java" Watch "how to run unix pipe from mkisofs and cdrecord in windows with java" New topic
Author

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

benny rusli
Ranch Hand

Joined: Jan 15, 2005
Posts: 72
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

Joined: Nov 04, 2004
Posts: 53
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

Joined: Jun 02, 2003
Posts: 1923

...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).


http://home.arcor.de/hirnstrom/bewerbung
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

"|" 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.


[Jess in Action][AskingGoodQuestions]
benny rusli
Ranch Hand

Joined: Jan 15, 2005
Posts: 72
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

Joined: Jun 02, 2003
Posts: 1923

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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to run unix pipe from mkisofs and cdrecord in windows with java
 
Similar Threads
problem executing this piped command
How to call Oracle sqlldr in Java
how getting console output into a JTextArea
Launching telnet using java program fails with Win 7 OS
How to close dos 'pause' command in Java