I have a problem with a Java program. I uses a tool "ugpc" to get the assembly structure and write it in a textfile. When i start the program under netbeans it writes these files without problem. but when i compile it to a jar file and run this jar, i get the error "Error: Fatal system Error 1020005" written in the proc.getErrorStream(); and no .txt file ist written in the ouput. Also in the ErrorStream appears that the textfile can not be found, but he should write it and not open it. My PC is new installed and before that formatting the tool was running good. I use Java 7. When I manually start the command via cmd it works also fine. We startet the tool under another user account and the same error appears.
Process proc = Runtime.getRuntime().exec("cmd /c " + "c:\\ugs\\nx6\\UGII\\ugpc -a -s2 " +"S:\\Geraete\\L\\0154\\E2\\6169-001000-201_Rev-E2_DWG.prt" + " > " + "S:\\LAUF5\\1\\6169-001000-201_Rev-E2_DWG.txt");
proc.waitFor();
Related
I am trying to loop into files, and run the script sh in each file using JAVA.
for (File file : files) {
if (file.isDirectory()) {
Runtime.getRuntime().exec("cmd.exe /c start "
+file.getAbsolutePath()+"\\creationNoPersisWF12.sh");
TimeUnit.SECONDS.sleep(1800);}}
The window of the script opens and get closed immediately.
However, when I try the execute the scripts sh from outside, they execute successfully.
I need some help please.
Process process = Runtime.getRuntime().exec("cmd.exe /c start "
+file.getAbsolutePath()+"\\creationNoPersisWF12.sh");
if(process.exitValue()!=0){
throw new RuntimeException(new String(process.getErrorStream().readAllBytes()));
}
you have to check the exit value and read the error stream for the errors since its a process on its own, it won't throw any error on its own after invoking the process you have to check if it ran successfully with exitvalue 0 or not.
I have just switched over to working on a mac and I am trying to determine why I am unable to get Eclipse to recognize the binary I am trying to run via a ProcessBuilder.
I have tried to run it both as a Java Application in Eclipse and as a TestNG test.
If I compile the class with java and run it directly from the command line it will work but not through Eclipse which leads me to believe the configuration for the $PATH is not setup correctly in my TestNG configuration.
Question
I am sure this is a configuration issue within Eclipse but after searching for a day and coming up short I wanted to post for some help. I have tried to set $PATH on the configuration but it does not seem to work.
Thank you
Update /Answer
It turned out that the PATH I had set on the shell shown below was not the same that Java had which I checked using the code below. After verifying that I then added the proper path to my environment on the ProcessBuilder and executed the script as shown in the answer.
Map<String, String> env = processBuilder.environment();
for (String key : env.keySet())
System.out.println(key + ": " + env.get(key));
Map<String, String> envs = processBuilder.environment();
System.out.println("Path " + envs.get("PATH"));
envs.put("PATH", "/usr/local/bin");
System.out.println("PATH " + envs.get("PATH"));
Code
File logsDir = new File(logDirectory);
if (!logsDir.exists()) {
logsDir.mkdirs();
}
// run process directly
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("appium");
processBuilder.redirectError(new File(logsDir, "appiumError.txt"));
processBuilder.redirectOutput(new File(logsDir, "appiumOutput.txt"));
process = processBuilder.start();
Output (it cannot find node to run appium hence the No such file or directory)
Caused by: java.io.IOException: Cannot run program "appium": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at AppiumService.startAppium(AppiumService.java:77)
Path (The bin for node and appium is in /usr/local/bin)
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:
/usr/local/opt/ant/bin:/usr/local/opt/maven/bin:
/usr/local/opt/gradle/bin
The PATH variable of the java-process might be explicitly set by Eclipse not containing the paths you need. You can call the command using the absolute path to the corresponding directory or you might try using a shell to start the process by creating the process with
processBuilder.command("/bin/sh", "-c", "appium");
I have Nodejs - server.js code in my windows system from which i want to execute a simple jar file.
So i used follwoing code :
cmd = "java -jar C:\\libs\\sample.jar";
var Exec =exec(cmd, function(error, stdout, stderr) {
if (error !== null) {
console.log('exec error: ' + error);
}//end of if
});//end of exec cmd
When i run the "node server.js" in command prompt ,jar is executing perfectly.
After this i made this "node server.js" command as service by referring following link :
https://github.com/coreybutler/node-windows
i.e node-windows,But now once its become service i am unable to exectue simple.jar,even i am enble to run simple "java -version" command.
Except java all other command are working fine even after i made nodejs as service.
Please help me out.....
New Update : After testing lot of different cases, Finally i came to know that jars containing JFrame components is not opening...how to solve this
I am trying to download a XML file from a FTP server with wget in my Java programm.
I have to wait until it finishes the download.
String command = "WGET -O "
+props.getProperty("xmlFolder")+""+
+ rs.getString("software")
+ ".xml ftp://"+props.getProperty("ftpUser")
+":"+props.getProperty("ftpPasswort")+"#"+rs.getString("xmlPfad");
System.out.println(command);
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
System.out.println("downloaded!");
Without the waitfor() it works perfectly, but with this function it stucks after 2-3 MB are downloaded. Any suggestions?
Have you tried to use the --quiet option for wget?
EDIT 1:
The pipe's write side (child process) might be full.
EDIT 2:
From openjdk-6-src-b20-21_jun_2010
In jdk/src/solaris/native/java/lang/UNIXProcess_md.c (at least for a UNIX system) we can see how Java launches a new child process and how it is using pipe to redirect stdout and stderr from child (wget) to parent process (Java)
I have a python compiled script (script.pyc , I haven't the .py file)that work well from my windows command prompt, and I want to execute it from my Java's application.
I tried to use runtime() method :
Runtime runtime = Runtime.getRuntime();
runtime.exec(new String[] {"C:\\toto\\tools\\script.pyc" ,"arg","arg2" });
but I get an error :
Exception in thread "main" java.io.IOException: Cannot run program "C:\Nuance\VoCon Hybrid\SDK_v4_3\tools\clctodict.pyc": CreateProcess error=193, %1 n?est pas une application Win32 valid
The script work well in my terminal ("arg" is a txt file, "arg2" is the output name, and the script does its job without any problem).
I also try to launch my script with getDesktop() :
File fie = new File("C:\\toto\\tools\\script.pyc" ,"arg","arg2");
Desktop.getDesktop().open(fie);
There is no problem, but I can't add argument, so I can just see a terminal windows opening during a few second before disappearing instantly.
I have also tried to use JPython, without success too (maybe we can't use methode "execfile" on a .pyc????)
You can do something like
Process p = Runtime.getRuntime().exec(new String[]{"python.exe" ... other args)
Then you can invoke p.waitFor() to wait for the end of the process and p.exitValue() to test if the program exited successfully.
You can also get the output stream via p.getOutputStream() to retrieve the text printed by your python script
Please refer to the class documentation for further information : http://docs.oracle.com/javase/6/docs/api/java/lang/Process.html
Just like you need a jvm to run a .class, you need a python interpreter to run a .pyc.
Try something like:
runtime.exec(new String[] {"c:\\Python26\\bin\\python.exe", "C:\\toto\\tools\\script.pyc" ,"arg","arg2" });