Hi
I am trying to execute the command string with Runtime.getRuntime.exec(String cmd).What
i'm actually trying to extract the I frames from video using the MPlayer and it is
installed in the different directory than that of my eclipse workspace.
I'm using the java code like the below
C:\\\Program Files\\\MPlayer for Windows mplayer file.mp4 -benchmark -noframedrop -ao null -vo jpeg:outdir=iframes -vf framestep=I
the actual command to extract using DOS is
"mplayer file.mp4 -benchmark -noframedrop -ao null -vo jpeg:outdir=iframes -vf framestep=I".
The ECLIPSE WORKSPACE is in my d: drive.And the Mplayer is in c:\program files\Mplayer for windows.
Eclipse IDE shows the exception as:-
Exception in thread "main" java.io.IOException: Cannot run program "C:\Program Files\MPlayer for Windows": CreateProcess error=5, Access is denied
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at myvideo1.main(myvideo1.java:39)
Any help is greatly appreciated.
Try this:
exec("\"C:\\Program Files\\MPlayer for Windows\\mplayer\" file.mp4 -benchmark -noframedrop -ao null -vo jpeg:outdir=iframes -vf framestep=I");
I surrounded the command in \" since the path contains spaces and added a missing \ in front of mplayer.
Related
I'm fiddling with opening external applications from Java source code. I am trying to open a launcher for a game called Runescape, which is found inside C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Jagex. The name of the file inside this directory is RuneScape Launcher.url.
This is the code which demonstrates my progress so far:
public static void main(String[] args) throws IOException, InterruptedException {
//doesn't work
Process p = Runtime.getRuntime().exec("C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Jagex\\RuneScape Launcher.url");
//if Chrome was to be opened, it works, since it is .exe
// Process p = Runtime.getRuntime().exec("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
p.waitFor();
System.out.println(p.exitValue());
}
The error that gets thrown is:
Exception in thread "main" java.io.IOException: Cannot run program "C:\ProgramData\Microsoft\Windows\Start": CreateProcess error=193, %1 is not a valid Win32 application
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at Main.main(Main.java:47)
Caused by: java.io.IOException: CreateProcess error=193, %1 is not a valid Win32 application
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more
Obviously, RuneScape Launcher.url is not a valid Win32 application. How to start such an application?
My research:
- this post suggests using ShellExecute, however it is written in another programming language. I couldn't find a similar solution for Java.
- this post talks about passing parameters when calling an external application, but that external application is .exe
- this page demonstrates calling external applications, but again only .exe
Then, I've tried starting this launcher from cmd manually ... successfully. First, I've located launcher directory: cd C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Jagex and then called the launcher: "RuneScape Launcher.url". This started the launcher correctly. Why doesn't it start from Java code?
Try passing the launcher as an argument to cmd.exe:
Process p = Runtime.getRuntime().exec("cmd.exe", "/c", "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Jagex\\RuneScape Launcher.url");
I want to make a file though the cmd in java using this code
Runtime.getRuntime().exec("mkdir C:\\Users\\Nick\\test");
and i get this annoying error:
Exception in thread "main" java.io.IOException: Cannot run program "mkdir": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at LFID.main(LFID.java:11)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more
I have no idea what's causing it so help.
By the way please don't tell me how to create a folder not through cmd, I need to do it this way. Thanks.
mkdir isn't a standalone executable you can launch as a separate process - it's a command that the Windows command shell understands.
So you could run cmd.exe /c mkdir ...:
Runtime.getRuntime().exec("cmd.exe /c mkdir c:\\Users\\Nick\\test");
Or:
Runtime.getRuntime().exec(
new String[] { "cmd.exe", "/c" "mkdir" "c:\\Users\\Nick\\test"});
... but I'd still recommend just using File.mkdir instead... why call out to an external process when you can do it within Java? (If you're going to specify an odd requirement, it helps to give some more context on it...)
Trying to use the python TweetNLP wrapper CMUTagger, but its throwing the following error:
java.io.FileNotFoundException: \dev\stdin (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at cmu.arktweetnlp.util.BasicFileIO.openFileToReadUTF8(BasicFileIO.java:50)
at cmu.arktweetnlp.RunTagger.runTagger(RunTagger.java:93)
at cmu.arktweetnlp.RunTagger.main(RunTagger.java:364)
Sep 17, 2014 10:22:45 AM cmu.arktweetnlp.util.BasicFileIO openFileToReadUTF8
SEVERE: Could not open file:/dev/stdin
Reinstalled the JDK instead of the JRE only. Didn't fix a thing. Not sure what to do as i cant even locate the dev folder in the java directory... halp =(
Executes java program fine if the cmd line call without python is 'sh', 'runTagger.sh', '--output-format', 'conll', [File with tweets to tag], but i need it to tag incoming stream of tweets from python via stdin =)
EDIT found the dev/stdin in CygWin and tried adding the paths 'c:...\cygwin' and 'c:...\cygwin\dev' but again nothing happened
I was stuck on this forever as well. I found a workaround for it.
You could use the following code:
import subprocess
p = subprocess.check_output('java -XX:ParallelGCThreads=2 -Xmx500m -jar ark-tweet-nlp-0.3.2.jar examples/example_tweets.txt')
this will give you output for running the example_tweets file through the tagger.
I'm developing a java desktop application to access information, format, change labels and volume id. This app's target are Windows users that will be using mainly Windows XP or Windows 7.
I'm getting basic info using java's File and FileSystemView; and I'm using Runtime.getRuntime().exec() to execute external Windows applications to do the other tasks.
I tried to use 'vol' and 'dir' to get the volumeId information but I get the following error:
Starting: vol E:
java.io.IOException: Cannot run program "vol": CreateProcess error=2, O sistema não pode encontrar o arquivo especificado
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at app.CommandRunnerWithReturn.run(CommandRunnerWithReturn.java:24)
Caused by: java.io.IOException: CreateProcess error=2, O sistema não pode encontrar o arquivo especificado
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more
Is there a Java API or Windows program I can use to get volumeid info?
Thanks in advance.
Some commands are built in to a shell. To run these commands you need to run the shell to run the command. For CMD you need something like
CMD /C VOL
for unix shell you need something like
sh -c "cd /path ; command > file"
I am in the folder :
/cygdrive/d/ragsxq where I have kept some simple X-Query stmts to be executed via Saxon X-Query engine...(Saxon 9.4 HE )
The following statement :
$ java -classpath /cygdrive/d/saxon/saxon9he.jar net.sf.saxon.Query -q:ragsXQuery.xq
gives :
java.lang.NoClassDefFoundError: net/sf/saxon/Query Caused by:
java.lang.ClassNotFoundException: net.sf.saxon.Query at
java.net.URLClassLoader$1.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class:
net.sf.saxon.Query. Program will exit. Exception in thread "main"
But the below statement works fine:
$ java -classpath ../saxon/saxon9he.jar net.sf.saxon.Query -q:ragsXQuery.xq
?!?!
Something to do with the Class-loader..?? Permmissions..?? Cygwin ? Hmmmmm...
Thanks a lot for pointing out this Cygwin behavior!
But the strange thing is, i run into this java.lang.NoClassDefFoundError (exactly the same as above) when I try to Run an Xquery via my Eclipse (Indigo) on Mac OS Lion too...via the XQDT plugin, where I have to configure the XQuery engine by providing the full-path of the saxon9he.jar & the main-class viz., net.sf.saxon.Query
Note that a similar set-up on Windows-XP works fine.
This time, I guess it could be some Classpath issue or the way Mac OS's Java treats things differently ?
I think I have faced this before. It is probably a Cygwin nuance. Just try
$ java -classpath `cygpath -m /cygdrive/d/saxon/saxon9he.jar` net.sf.saxon.Query -q:ragsXQuery.xq
Here is a possible explanation as to why:
http://cygwin.com/ml/cygwin/2008-01/msg00083.html
Below is the output from my Cygwin for an executable JAR file. I use Windows Vista 32 bit (I know, it sucks).
adarshr$ java -jar /cygdrive/d/adarshr/data/cf.jar
Error: Unable to access jarfile /cygdrive/d/adarshr/data/cf.jar
adarshr$
adarshr$ java -jar `cygpath -m /cygdrive/d/adarshr/data/cf.jar`
Usage: java -jar cf.jar SEARCH [DIRECTORY] [OPTIONS]...
Try -h or --help for more information
As you can see, the second command worked and printed a help (as expected).