processbuilder

Java application lauched with ProcessBuilder blocked after some time

半城伤御伤魂 提交于 2019-12-08 03:02:23
问题 I am developing a Java desktop application (let's call it console) containing 3 buttons: two of them launch a Win32 applications; the third should launch an executable jar: ProcessBuilder pb = new ProcessBuilder("java", "-jar", testDrivePath); Process process = pb.start(); where testDrivePath is the path to the jar (something like "C:\Programs\TestDrive.jar") The TestDrive.jar application launches correctly, but after some time it blocks and is not able to make any operation. If I close the

Java processbuilder and using environment variables

纵饮孤独 提交于 2019-12-07 16:59:34
问题 What I want to do is I want to run a process, however because this process itself relies on environment variables, directly calling it causes error within the process. For those who are wondering what this is, it's rake tool. For this reason I thought maybe it's better to use bash and using it through bash would eliminate the issue. However that doesn't seem to be the case. Here is my code: public static void runPB(String directory) throws IOException { ProcessBuilder processBuilder = new

Cannot launch shell script with arguments using Java ProcessBuilder

家住魔仙堡 提交于 2019-12-07 15:05:11
问题 I am trying to execute a shell script with command line arguments using ProcessBuilder, this shell script inturn calls two other shell scripts that uses this argument. The first shell script runs fine, but when the second one is started it returns exit code 1. ProcessBuilder snippet from Java Program: //scenario - A string that holds a numerical value like 1 or 2 etc String[] command2 = {"/bin/bash", "<path to shell script>/runTemporaryTestSuite.sh", scenario}; ProcessBuilder pb2 = new

bash unix processbuilder from java not running

梦想的初衷 提交于 2019-12-07 13:30:46
问题 I want to execute a simple Unix command from my Java servlet: what I need to do is a simple echo write to file like this one: echo HELLO > myfile.txt What I'm doing in my servlet is: import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class ServletAutorecovery extends HttpServlet { protected void processRequest

Executing an external program using process builder or apache commons exec

余生颓废 提交于 2019-12-07 13:25:59
问题 I need to execute an external application which returns large data (takes more than 2 hours to complete ) nand which continuously outputs data. What I need to do is execute this program asynchronously and capture the output in a file. I tried using java process builder, however it seems to hang and return output only when the program is exited or forcefully terminated. I tried to use process builder and spwaned a new thread to capture the output, but still it did not help. Then I read about

Java Processbuilder Stream to Python-Script

送分小仙女□ 提交于 2019-12-06 15:40:40
I have a minor Problem with a small Project I'm trying to do. I'm trying to use a Java-Program to call a Python-Script. Java: ProcessBuilder pb = new ProcessBuilder("python3", "tmp.py"); process = pb.start(); OutputStream stdin = process.getOutputStream(); InputStream stderr = process.getErrorStream(); InputStream stdout = process.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(stdout)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin)); writer.write("example" + "\n"); String output = reader.readLine(); Python-Script tmp.py (example):

ProcessBuilder gets stuck after getting an error

倖福魔咒の 提交于 2019-12-06 13:21:36
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.println("Returned Value :" + process.exitValue()); but my program gets stuck inside while loop. The

Process.waitFor() a thread

£可爱£侵袭症+ 提交于 2019-12-06 13:04:08
While running an external script, I want to read the ErrorStream and OutputStream of this script both simultaneously and separately and then process them further. Therefore, I start a Thread for one of the streams. Unfortunately, the Process doesn't seem to waitFor the Thread to be terminated, but return after the non-threaded stream has no further input. In a nutshell, here is what I am doing: ProcessBuilder pb = new ProcessBuilder(script); final Process p = pb.start(); new Thread(new Runnable() { public void run() { BufferedReader br = new BufferedReader(new InputStreamReader(p

How to run NPM Command in Java using Process Builder

筅森魡賤 提交于 2019-12-06 09:30:35
问题 import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.*; public class TestUnZip { public static void main(String[] args) throws IOException, InterruptedException{ String destFolder="E:\\TestScript"; /* * Location where the Nodejs

How to execute cmd commands via Java swing

孤街浪徒 提交于 2019-12-06 09:16:43
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 method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold