runtime.exec

Is there an alternative to Runtime.getRuntime().exec()

折月煮酒 提交于 2019-12-08 17:43:30
问题 Just wondering, if there is something better, newer, safer, faster, etc than Runtime.getRuntime().exec() . I want to run another process from my application on linux, and this is the only way i know how. Would be nice to have an alternative. 回答1: How about ProcessBuilder? A bit more: Introduced in Java 1.5, allows you to gain more control on the process environment - set the working directory, let you redirect the error stream to the input stream (from java POV) and a few more things. From

java Runtime process - check if waiting for input

不问归期 提交于 2019-12-08 16:44:01
问题 I wish to create a process using java's runtime: for example. Process proc = Runtime.getRuntime().exec("cmd"); Then, I want to somehow wait for the process until it is in 'ready for input' state, which will verify it has finished all of its work. Anyway on how to do it? One thing that is possible is echoing "---finished---" and checking if this line was written using the stdin of the process. But I dislike the idea. Is there any better (more formal) approach to do this? By the way, I need

How can I start a second Java process?

浪尽此生 提交于 2019-12-08 16:33:31
问题 How can I start a second Java process platform independent? Ideally it should be the same Java version that currently running. Are there any helpful system properties? 回答1: It is not possible, in general. The recipe provided in @khachik's answer will not necessarily work for a non Sun implementation of Java. The java executable is not necessarily called java and doesn't necessarily live in the bin subdirectory. Even with Sun Java, on Windows there are two executables; java and javaw . The

Java unable to open pdf using Runtime

Deadly 提交于 2019-12-08 14:46:27
问题 I have to open a pdf on clicking a JMenuItem. I can open the pdf on click the menu item if i run my program from netbeans. But when i run from jar file it is not opening. I clean and build my project. But no change. Running when run from netbeans but not running from jar file. Do i need to add some library. My codes are as follows m_aboutItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Runtime rt = Runtime.getRuntime(); //System.out.println(Menubar1

problem with ImageMagick And Java Runtime Exec

别来无恙 提交于 2019-12-08 13:44:47
问题 I Have a bit of a strange problem no java expert i know could solve .. i need to used imagemagick on my application to make the emails on my website converted to images so no pot can take the emails easily .. the problem solved with image magick command line as following convert -size 200x30 xc:transparent -font /home/emad/TITUSCBZ.TTF -fill black -pointsize 12 -draw "text 5,15 'emadhegab@hotmail.com'" /home/emad/test.png and it work like magic really and so i tried to put that on the java to

How to run a .jar file from within Java program?

别等时光非礼了梦想. 提交于 2019-12-08 09:15:37
问题 What I'm basically trying to do here, is run a .jar file which is located under C/Users/-any user here-/appdata/Roaming/-my folder here-/-file name here-.jar Do I somehow open a CMD and do: cd appdata/Roaming/<Folder> java -jar <FileName>.jar This seems to work when I type it into CMD itself. I can't seem to make it work when running from java program. I tried to do: Runtime.getRuntime().exec("cd appdata/Roaming"); And I get an error that the specified directory doesn't exist. 回答1: Use an

How to know whether SFTP was successful or not in WinSCP

﹥>﹥吖頭↗ 提交于 2019-12-08 07:52:00
问题 I am using below code to run SFTP command through Jsch: public void putfile(){ try { String command="winscp /script=D:\\command.txt" ; System.out.println(command); Runtime rt=Runtime.getRuntime(); rt.exec(command); } catch(Exception e) { System.out.println("Exception in index.jsp:"+e.getMessage()); } } I am putting sample.zip from local machine to Unix Server, The command.txt contains: option confirm off open sftp:User:password@IP get G:\sample.zip /MyFolderLocation/ exit Its working fine but

java runtime.exec cmd /c parsing quoted arguments

允我心安 提交于 2019-12-08 07:17:22
问题 I'm trying to run runtime.exec(String[],null, new File(directory)) with the first two arguments being "cmd" and "/c". I'm trying to specify the version of java for my tomcat to run. It appears that the cmd /c arguments are causing runtime.exec to parse all of the arguments by space delineation or probably more appropriately cmd is parsing each argument out. So, cmd /c .\bin\Tomcat7.exe //US//Tomcat7 --Jvm="C:\Program Files\Apache Tomcat 7\jre\bin\server\jvm.dll" is getting the jvm argument

Running a program from within Java code

徘徊边缘 提交于 2019-12-08 04:13:19
问题 What is the simplest way to call a program from with a piece of Java code? (The program I want to run is aiSee and it can be run from command line or from Windows GUI; and I am on Vista but the code will also be run on Linux systems). 回答1: Take a look at Process and Runtime classes. Keep in mind that what you are trying to accomplish is probably not platform independent. Here is a little piece of code that might be helpful: public class YourClass { public static void main(String args[])

Java Runtime Exec for VBA script with arguments

风流意气都作罢 提交于 2019-12-07 23:20:30
问题 I am trying to use Runtime exec() to run a vba script with arguements. I am having trouble passing in the args. I think I need to use the String[] overloaded method for exec. Currently this works: String command = "cmd /c \"\\concat2.vbs\"" Process p = Runtime.getRuntime().exec(command); But I want to run that with arguments and if I do this String command = "cmd /c \"\\concat2.vbs\" " + arg1 + " " + arg2 where arg1 and arg2 are strings my program doesnt run (status = 1) 回答1: I think I need