I'm trying to use processbuilder to spawn a new JVM in eclipse with java 7 u51. Unfortunately, I am having a problem with the path ( String path = System.getProperty("java.home"); ) when the processBuilder attempts to use it.
Here is the problem code
String separator = System.getProperty("file.separator");
String classpath = System.getProperty("java.class.path");
String path = System.getProperty("java.home");
System.out.println("Seperator = " + separator + " classpath = " + classpath + " path = " + path);
ProcessBuilder processBuilder = new ProcessBuilder(path, "-cp",
classpath, Transcriber.class.getName());
Process process = processBuilder.start();
Here is a look at the console output
java.io.IOException: Cannot run program "C:\Program Files\Java\jre7": CreateProcess error=5, Access is denied
Unable to call transcribeConvo
at java.lang.ProcessBuilder.start(Unknown Source)
at TranscribePanel$2.run(TranscribePanel.java:131)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: CreateProcess error=5, Access is denied
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 7 more
I tried adding the jvm.dll directly to the eclipse.ini but it didn't have an affect. Any help would be great. Thank you :)
Ps: If I didn't provide enough information please let me know.
The path "C:\Program Files\Java\jre7" is not the path to an executable file, hence the error. if you want to execute the java executable, then you need to actually provide the full path to it, probably "C:\Program Files\Java\jre7\bin\java.exe."
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...)
i have a path where i have shell script which i have to execute using java program but i am getting error as .
Runtime.java
public class Runtime {
public static void main(String[] args) {
System.out.println("Triggered");
try {
Process p = Runtime.getRuntime().exec("\"http://192.168.1.7/sh_scripts/check_process/2.sh\"");
System.out.println(p);
} catch (IOException e) {
e.printStackTrace();
}
}
}
LOGCAT
http://192.168.1.7/sh_scripts/check_process/2.sh: 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 com.howtodoinjava.demo.poi.Runtiime.main(Runtiime.java:15)
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
Did i miss anything while executing . The path is not geeting read from the java program to execute the shell script So please help me to execute the jar file using the given http link where i can execute the 2.sh file successfully using java
As far as I know, you can only execute an executable FILE on the same computer, there is no support for downloading a script from a remote server in http, ftp or whatever else.
Same is true also in a normal unix shell.
So, you have a few options :
Download the .sh file yourself in java, put it in a temporary file, and execute it there
Run another .sh file that downloads the .sh file from http and executes it; can be a oneliner, like source <(curl -s http://192.168.1.7/sh_scripts/check_process/2.sh)
Try to execute this oneliner, maybe using ProcessBuilder can ease the creation of the redirection etc.. but I'm not sure.
I am new to using AWS SDK on Java. I have created a program to create AWS instances from Java and to check if its running. But I am not able to figure out how to run a bash command on that running instance. Please help!
try
{
String lscmd = "ls";
Process p=Runtime.getRuntime().exec(lscmd);
p.waitFor();
BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
while(line!=null)
{
System.out.println(line);
line=reader.readLine();
}
}
catch(IOException e1) {
e1.printStackTrace();
}
catch(InterruptedException e2) {
System.out.println("Pblm found2.");
}
But I get an error saying,
java.io.IOException: Cannot run program "ls": 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 ListInstances.main(ListInstances.java:79)
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.(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more
I am not sure how to connect to the instance I created and run this command on that instance.
Could it be that the PATH is not defined and it doesn't know where to find ls? Try with the full path (e.g. /bin/ls) to verify.
I'm trying to run XMLBeans:
scomp -compiler "C:\Program Files (x86)\Java\jdk1.6.0_37\bin\javac.exe" -cp "C:\Components\*";"C:\Components\jsr173_api.jar";"C:\xmlbeans\lib\xbean.jar";"C:\xmlbeans\lib\xbean_xpath.jar";"C:\xmlbeans\lib\jaxen-1.1-beta-2.jar;" -out S2002PDPIn.jar S2002PDPIn.xsd
It gets an error below:
java.io.IOException: Cannot run program "C:\xmlbeans\bin\jar":
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 org.apache.xmlbeans.impl.tool.CodeGenUtil.externalJar(CodeGenUtil.java:304)
at org.apache.xmlbeans.impl.tool.SchemaCompiler.compile(SchemaCompiler.java:841)
at org.apache.xmlbeans.impl.tool.SchemaCompiler.main(SchemaCompiler.java:272)
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)
... 6 more
BUILD FAILED
At first I thought the "C:\xmlbeans\bin\jar" it was looking for was a directory so I just created a folder "jar", but when I run it again the "jar" was referred as a file where I get error:
java.io.IOException: Cannot run program "C:\xmlbeans\bin\jar":
CreateProcess error=5, Access is denied
Please kindly help me how to fix this so that it don't look for "jar" file.
I looked "scomp.cmd" but there is no line that will do this.
Thank you in advance.
You are simply calling more applications, than you expect:
scomp -compiler "C:\Program Files (x86)\Java\jdk1.6.0_37\bin\javac.exe" -cp "C:\Components\*";
"C:\Components\jsr173_api.jar";
"C:\xmlbeans\lib\xbean.jar";
"C:\xmlbeans\lib\xbean_xpath.jar";
"C:\xmlbeans\lib\jaxen-1.1-beta-2.jar;" -out S2002PDPIn.jar S2002PDPIn.xsd
This happens because of ";", you would have to enclose the complete classpath with one " and seperate the values by ;.