runtime.exec

capture error from runtime process java

微笑、不失礼 提交于 2020-03-23 04:05:53
问题 I'm running a Java program from another Java application using Runtime.getRuntime().exec like this Process p1 = Runtime.getRuntime().exec("javac test.java"); Process p2 = Runtime.getRuntime().exec("java test"); The content of the test.java import java.io.*; class test { public static void main(String args[]) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); System.out.println(s); } } I want to handle Input , Output and Error stream of the process p2 . I did capture of the

capture error from runtime process java

拥有回忆 提交于 2020-03-23 04:05:08
问题 I'm running a Java program from another Java application using Runtime.getRuntime().exec like this Process p1 = Runtime.getRuntime().exec("javac test.java"); Process p2 = Runtime.getRuntime().exec("java test"); The content of the test.java import java.io.*; class test { public static void main(String args[]) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); System.out.println(s); } } I want to handle Input , Output and Error stream of the process p2 . I did capture of the

Runtime.getRuntime.exec() hangs on same command that it runs in different situations

*爱你&永不变心* 提交于 2020-02-22 06:10:48
问题 I'm having an interesting problem when I use Runtime.getRuntime.exec() to run a command from Java. The following part of my code basically converts doc file to txt file. catdoc is a tool that converts input file to text stream and outputs it to the standard output. The ouput than redirected to a txt file. It works perfectly fine for some document files, however it hangs for some certain document files. String[] strArr1 = new String[]{"catdoc", docFilePath}; Process p1= Runtime.getRuntime()

Runtime.getRuntime.exec() hangs on same command that it runs in different situations

眉间皱痕 提交于 2020-02-22 06:10:48
问题 I'm having an interesting problem when I use Runtime.getRuntime.exec() to run a command from Java. The following part of my code basically converts doc file to txt file. catdoc is a tool that converts input file to text stream and outputs it to the standard output. The ouput than redirected to a txt file. It works perfectly fine for some document files, however it hangs for some certain document files. String[] strArr1 = new String[]{"catdoc", docFilePath}; Process p1= Runtime.getRuntime()

Runtime.getRuntime.exec() hangs on same command that it runs in different situations

会有一股神秘感。 提交于 2020-02-22 06:05:12
问题 I'm having an interesting problem when I use Runtime.getRuntime.exec() to run a command from Java. The following part of my code basically converts doc file to txt file. catdoc is a tool that converts input file to text stream and outputs it to the standard output. The ouput than redirected to a txt file. It works perfectly fine for some document files, however it hangs for some certain document files. String[] strArr1 = new String[]{"catdoc", docFilePath}; Process p1= Runtime.getRuntime()

Creating a “.bat” file, run it and delete it from Java

僤鯓⒐⒋嵵緔 提交于 2020-01-26 00:40:12
问题 I'm making a .bat dynamically in Java . After creating the file and exectuing it, I want to delete it. In order to make sure that delete() will be executing after running the .bat file, I delete the file within a different thread. Is this a good approach for this task? How would you implement it in a better way? final File file = new File("run.bat"); file.createNewFile(); PrintWriter writer = new PrintWriter(file, "UTF-8"); writer.println(COMMAND1); writer.println(COMMAND2); .... ANOTHER

Run processbuilder and get in and output

≡放荡痞女 提交于 2020-01-17 04:33:05
问题 I'm trying to get my program to launch Enchanter to SSH into my server, but can't seem to figure out how to get in and output to go to stdin and stdout , or anywhere for that matter. I just get a blank output window in Netbeans. How to I get the Jar to run, and get input/output? public class openShell { public void openShell() throws IOException { String line; Scanner scan = new Scanner(System.in); ProcessBuilder builder = new ProcessBuilder ("C:\\Program Files\\Java\\lib\\enchanter-beanshell

Runtime.exec() from tomcat6 succeeds, but cannot access any files

女生的网名这么多〃 提交于 2020-01-17 03:04:28
问题 I'm moving our servlets (pure Java, running in Tomcat 6) from CentOS to Debian, and faced the problem with executing commands with Runtime.exec() . (The command should be ImageMagick's convert in production, but I have simplified the calls to find the source of problems, so all the following code with echo is tested and not working as well). String command = "echo test123 > /tmp/tomcat6-tmp/1"; Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec(command); int exitVal =

Java's System.getRuntime().exec not behaving as if the shell user called it

﹥>﹥吖頭↗ 提交于 2020-01-15 10:47:08
问题 I am running a java application from the console on an HP-UX machine. In it, I generate some reports, zip them, and then email them. Everything is working, except the email. I am using the mail binary to send mail from the command line. Since it's HP-UX, it's a bit different than the standard GNU sendmail. This is the code I'm using to send the mail: public static void EmailReports(String[] recipients, String reportArchive, String subject){ SimpleDateFormat dateFormat = new SimpleDateFormat(

Is there a way to generate the 8.3 or 'short' (Windows) version of a file name in Java?

Deadly 提交于 2020-01-15 08:23:41
问题 In our application, we are allowing users to open files and directories. Java 6 provides us with... java.awt.Desktop.getDesktop().open(file); which works great. However, since we need to ensure Java 5 compatibility, we also implement a method of opening files by calling the start command in cmd.exe ... String command = "cmd.exe start ..."; Runtime.getRuntime().exec(command); This is where the problem shows up. It seems that the start command can only handle 8.3 file names, which means that