It's not a secret anymore!
The moose likes Java in General and the fly likes Runtime.exec() question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Runtime.exec() question" Watch "Runtime.exec() question" New topic

Runtime.exec() question

Cuneyt Taskiran

Joined: Sep 18, 2008
Posts: 11
I am trying to run the VideoLAN media player from withing my program using:

When this runs, VLC gives me an error for the second argument (the sout one). However, when I copy and paste the same command to the command line it works well. What am I missing? Should I escape singe quotes?

Thanks for the help,

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 44494
Don't know. But nobody should even think of going near Runtime.exec() without reading the classic paper by Michael Daconta. Google for "when Runtime.exec() won't".
Using a destroy() method looks suspect, even though that destroy() method isn't deprecated.
The ProcessBuilder class may make it easier to run a Process.
Carey Evans
Ranch Hand

Joined: May 27, 2008
Posts: 225

When using Runtime.exec() (or ProcessBuilder) you do not need to add any extra quoting to the command line arguments, like the single quotes in the --sout line. Try taking them out, then read Michael Daconta's paper.
Cuneyt Taskiran

Joined: Sep 18, 2008
Posts: 11
Getting rid of the single quotes in the --sout part of the command solved the problem.

I agree that destroy() is not an elegant way to terminate the process, will look into ProcessBuilder.
I agree. Here's the link:
subject: Runtime.exec() question
It's not a secret anymore!