processbuilder

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

怎甘沉沦 提交于 2019-12-06 06:09:59
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 happening in there...but nothing doing). The script runs fine from command line, using same command as I'm

Java ProcessBuilder showing console of started java application?

回眸只為那壹抹淺笑 提交于 2019-12-06 06:07:39
I have a JAVA application that launches (using ProcessBuilder) another JAVA application like this: String val = "something"; ProcessBuilder processBuilder = new ProcessBuilder("java", "-classpath", dir, appName, val); Process p = processBuilder.start(); Now, this works fine, appName is launched with the parameter val and it runs and works ... great ... the problem is no Console Window appears ... appName does a LOT of outputting to the console and we need to see it ... how can I start the process with a console? I am trying stuff like ("CMD.exe", "java", "-classpath", dir, appName, val), etc..

Process builder output and error redirection

我的未来我决定 提交于 2019-12-06 05:49:08
I am using ProcessBuilder to run an executable file from another directory. I'm also redirecting output and error to files in the local directory. But strangely my error file shows the output of the executable and the output file is blank. I am not sure what is going on, can someone please shed some light on my situation. My code: File outputFile = new File("outputLog.txt"); File errorFile = new File("ErrLog.txt"); List<String> command = Arrays.asList("c:\\dataloader\\TestDataLoader.exe", "-h"); ProcessBuilder probuilder = new ProcessBuilder(command); //redirect output probuilder

Error trying to mock constructor for ProcessBuilder using PowerMockito

不打扰是莪最后的温柔 提交于 2019-12-06 05:08:54
I am trying to mock the constructor for ProcessBuilder. The problem is that when the constructor is called it return null. Class code: public static void enable() throws IOException, InterruptedException { logger.info("Enable NTP server..."); String ntpAddress = AppConfig.getInstance().getString(AppConfig.NTP_SERVER, ""); AppConfig.getInstance().getBoolean(AppConfig.NTP_ENABLED, true); String enableNtp = "chkconfig ntpd on " + SEPARATOR + " service ntpd stop " + SEPARATOR + " ntpdate " + ntpAddress + " " + SEPARATOR + " service ntpd start"; String[] commandArr = {"bash", "-c", enableNtp};

Java - start another class' main in a different process

↘锁芯ラ 提交于 2019-12-06 04:58:14
问题 I need a clean way to start many instances of a Java program with a GUI, and I want to do it programmatically. The "program" i want to run is just a .class file (a compiled .java file with a main method), it should show a GUI and run independently from the others (as its own process). I also need to pass that program some arguments. Check EDIT5 for the complete working solution code. Here's the class that's supposed to start the many processes package startothermain; import java.io

bash unix processbuilder from java not running

痞子三分冷 提交于 2019-12-06 03:46:33
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(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response

Executing an external program using process builder or apache commons exec

ⅰ亾dé卋堺 提交于 2019-12-06 01:03:04
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 apache commons exec and tried the same . however this also seems to be taking a long time and returns

Cannot launch shell script with arguments using Java ProcessBuilder

与世无争的帅哥 提交于 2019-12-05 22:29:39
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 ProcessBuilder(command2); Process p2 = pb2.start(); BufferedReader br = new BufferedReader(new

Running bat file with java processbuilder

北战南征 提交于 2019-12-05 20:33:37
I am trying to execute .bat file using java process builder but it does not starts the process. Please tell me what i am doing wrong here. This code works fine with linux envoirnment when I replace file.bat with ./file.sh final ArrayList<String> command = new ArrayList<String>(); command.add(WORKING_DIR+File.separator+"file.bat"); final ProcessBuilder builder = new ProcessBuilder(command); try { builder.redirectErrorStream(true); builder.start(); } catch (IOException e) { logger.error("Could not start process." ,e); } First element in array must be an executable. So you have to invoke cmd.exe

Correct Usage of ProcessBuilder

此生再无相见时 提交于 2019-12-05 19:34:31
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 to stdout would it be acceptable to just have the parent process swallow the stdout stream, and then