processbuilder

Run java.exe through ProcessBuilder leads to application hanging?

不羁岁月 提交于 2019-12-24 07:16:39
问题 I have the following code: ProcessBuilder pb = new ProcessBuilder("C:\\Program Files\\Java\\jdk1.8.0_111\\bin\\java", "-cp", "project_folder\\target\\classes", "package.ExternalProcess"); Process p = pb.start(); OutputStream processOutputStream = p.getOutputStream(); IOUtils.write("1" + System.lineSeparator(), processOutputStream); InputStream processInputStream = p.getInputStream(); System.out.println("--1--"); System.out.println(process.isAlive()); // outputs true String result = IOUtils

java processbuilder windows command wildcard

家住魔仙堡 提交于 2019-12-24 02:32:05
问题 I want to invoke a Windows command from Java. Using the following line works fine: ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/C", "find \"searchstr\" C://Workspace//inputFile.txt"); But I want to find the string in all text files under that location, tried it this way, ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/C", "find \"searchstr\" C://Workspace//*.txt"); But it does not work and there is no output in the Java console. What's the solution? 回答1: It looks like find is

java processbuilder windows command wildcard

半世苍凉 提交于 2019-12-24 02:31:37
问题 I want to invoke a Windows command from Java. Using the following line works fine: ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/C", "find \"searchstr\" C://Workspace//inputFile.txt"); But I want to find the string in all text files under that location, tried it this way, ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/C", "find \"searchstr\" C://Workspace//*.txt"); But it does not work and there is no output in the Java console. What's the solution? 回答1: It looks like find is

java process builder add path to environment not working

天大地大妈咪最大 提交于 2019-12-24 01:04:33
问题 I have a problem with adding a path to the environment of a process using processbuider. I have no clue why the process is ignoring the environment. Here is my example: import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Map; public class main { public static void main(String [ ] args) { try { String s = null; ProcessBuilder pb = new ProcessBuilder("/bin/bash", "-c", "fsl"); Map<String, String> env; env = pb.environment(); env.put("FSLDIR", "/usr/local/fsl/bin/")

Java Stop Process and Close Streams

本秂侑毒 提交于 2019-12-23 21:13:35
问题 I'm using ProcessBuilder to launch an external process, but I need to be able to kill it. Right now I have no problem killing the process but for some reason the error stream doesn't close so the thread reading the stream never finishes. This keeps me from closing my program. Here's where I start the threads reading from the input and error streams. final Thread inputPrinter = new Thread() { public void run() { BufferedReader inputStream = new BufferedReader(new InputStreamReader(builder

Java ProcessBuilder: space within quotation marks

喜你入骨 提交于 2019-12-23 17:43:15
问题 I am using ProcessBuilder to run FFMPEG to convert and label some of my MP3-Files. Manually using the following in a .bat file works as expected: "E:\Dokumente\workspace\MusicBot\ffmpeg\bin\ffmpeg.exe" -i "The Glitch Mob - We Can Make The World Stop.mp4" -metadata author="The Glitch Mob" -metadata title="We Can Make The World Stop" -ab 320k "mob.mp3" Now what i am trying to achieve using java's ProcessBuilder ProcessBuilder pr = new ProcessBuilder(FFMPEG_PATH, "-i", target.getAbsolutePath(),

How to execute cmd commands via Java swing

做~自己de王妃 提交于 2019-12-22 18:38:16
问题 I have a file to print and I want to send him a custom water mark via java swing. i have 2 files NewJFrame.java and Test.java package test; import java.io.IOException; import java.io.OutputStream; /** * * @author shaharnakash */ public class NewJFrame extends javax.swing.JFrame { /** * Creates new form NewJFrame */ public NewJFrame() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this

ProcessBuilder gets stuck after getting an error

 ̄綄美尐妖づ 提交于 2019-12-22 18:04:21
问题 I am trying to execute a .bat file remotely and implementing following lines of code: ProcessBuilder processBuilder = new ProcessBuilder(command); final Process process = processBuilder.start(); InputStream stderr = process.getErrorStream(); InputStreamReader isr = new InputStreamReader(stderr); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { System.out.println(line); } process.waitFor(); System.out.println("Waiting ..."); System.out

ProcessBuilder.start() returns 0 but doesn't execute shell script

我是研究僧i 提交于 2019-12-22 12:48:33
问题 I'm trying to use ProcessBuilder to execute a shell script on my Linux server, from a Servlet running on WebSphere Application Server. The code returns 0 (using .waitFor()), but the script doesn't appear to execute. If I put an invalid path to the script I get a "file not found" exception, so I know it's finding the script...but doesn't appear to execute. The script itself calls another script that should eventually output a zip file (i've also got a 'touch' line to see if anything's

Correct Usage of ProcessBuilder

痴心易碎 提交于 2019-12-22 10:52:07
问题 After researching I have noticed that the "correct" way to use java's ProcessBuilder is to spawn two other threads to manage gobbling up the stdout/stderr of the newly created process so that it doesn't hang as is shown here : javaworld article But this has left me wondering about 2 questions- 1.) Why exactly are seperate processes needed instead of having the parent process gobble up the stdout and then sequentially the stderr? 2.) In addition, if you were to redirect the streams to both go