processbuilder

Call an exe from Java with passing parameters with writing to stdout and reading from stdin

给你一囗甜甜゛ 提交于 2019-11-29 18:09:48
I have read this question: Java Programming: call an exe from Java and passing parameters And this answer is good enough https://stackoverflow.com/a/5604756/2674303 But I additionally want to pass parameters to stdin of external process and read from stdout of this process. How can I do this? My efforts : main method: public class ProcessBuilderTest { public static void main(String[] args) throws IOException, InterruptedException { ProcessBuilder pb = new ProcessBuilder("C:\\Program Files\\Java\\jdk1.8.0_111\\bin\\java", "-cp", //class path key "C:\\Users\\redwhite\\IdeaProjects\\HelloMyWorld\

Error: Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified. Applies for all executables

谁说胖子不能爱 提交于 2019-11-29 15:02:08
My goal is to run SVN commands from java for one of my requirements, for the same i have already installed TortoiseSVN command line tool. Added the appropriate path"C:/Program Files"/TortoiseSVN/bin" to my environment "Path" variable. With the above setup, i can run my svn commands from windows command line using say "svn --version" and it works perfectly fine. Now coming back to the code to execute the same, i am using processbuilder for this. However i end up with the above error - java.io.IOException: Cannot run program "svn --version": CreateProcess error=2, The system cannot find the file

Building a process pipe with ProcessBuilder in Java 7

為{幸葍}努か 提交于 2019-11-29 13:35:16
I've been trying to figure out how to pipe a few processes in Java using the new ProcessBuilder . I can't find a suitable example of what I want to do and when I try to do it myself the process just hangs. I would appreciate a very simple example of some code that runs the equivalent of cat test.txt | wc , but not through a shell. --Update-- OK, just to clarify. I know there are ways to simulate a pipe by reading and writing streams. I'm wondering if that's done in some automatic way by the redirectInput and redirectOutput methods introduced in Java 7. You don't need a pipe in this case. "grep

Java execute process on linux

有些话、适合烂在心里 提交于 2019-11-29 11:40:44
I've been struggling for a while now with this problem and i can't seem to fix it. i already have tried different approaches (Runtime.exec(), ProcessBuiler) but none seem to work. This is my issue. I have a laptop which is always on. This laptop runs a java tool connected to an arduino via usb to turn on and off the lights in the house. i have created this program myself, therefore i'm also doing some regular maintenance work on it. Recently i have added a button to restart the program from my html interface (in case i have an update, or if for some other reason i might need to restart the

How to Terminate a Process Normally Created using ProcessBuilder

限于喜欢 提交于 2019-11-29 10:47:22
I am creating Processes using ProcessBuilder in my Java Application. The created process executes some FFMPEG commands which actually copy the RTSP streams in specified destination media file. ProcessBuilder builder = new ProcessBuilder("ffmpeg", "-i", RTSP_URL, "-f", fileFormat, destFilePath); Process processToExecute = builder.start(); I want to close the process before it completes its execution. So, If I run this FFMPEG command directly in windows CMD and then press 'CTRL+C' after 5 seconds then process get terminates with status '2'. And I can play the media file created so far. So, If I

ProcessBuilder can't find file?!

别说谁变了你拦得住时间么 提交于 2019-11-29 10:08:28
Another question in quick succession but this has to be a really obvious error that I am not seeing. I've written some code to run a batch file below but I'm getting an error message saying it cannot find the file but I can assure you that the file does exist in the directory! public class Pull { public void pullData() throws IOException { ProcessBuilder pb = new ProcessBuilder("adb.bat"); File f = new File("C:\\"); pb.directory(f); Process p = pb.start(); } public static void main(String[] args) throws IOException { Pull pull = new Pull(); pull.pullData(); } } and here is the error message

Java - ProcessBuilder command arguments with spaces and double-quotes fails

孤街醉人 提交于 2019-11-29 08:05:18
I'm using ProcessBuilder to run a Windows executable...the exact command I need to run is : "C:\Program Files\CCBU\CCBU.exe" -d"C:\My Data\projects\ccbu\ciccb-report.xls" -tf"C:\Program Files\CCBU\loss-billing-filters.txt" If I run the above command from a command prompt, it works fine. If I then issue the command and arguments as indicated in the following StackOverflow post ( ProcessBuilder adds extra quotes to command line ) as a String [] array it fails, as the spaces in the directory paths break the arguments somehow to the CCBU.exe executable : [log-snippet] 2015-08-31 10:39:08,937 [main

ProcessBuilder giving a “File not found” exception when the file does exist [duplicate]

雨燕双飞 提交于 2019-11-29 07:24:38
This question already has an answer here: ProcessBuilder gives a “No such file or directory” on Mac while Runtime().exec() works fine 1 answer Working on an application that will run on a Linux web server to delete logs from a certain directory, however I keep getting a FileNotFound exception. Here is the code: public static void deleteLOG() { try { ProcessBuilder probuilder = new ProcessBuilder("find /home/root/multicraft/servers/ -name '*.log' -delete"); probuilder.start(); } catch (IOException e) { e.printStackTrace(); } } And the exception java.io.IOException: Cannot run program "find .

ProcessBuilder vs Runtime.exec()

若如初见. 提交于 2019-11-29 05:55:49
Which one is better? By better I mean which one has better security, etc. (not ease of use). Ease of use is the only real difference between those two. Note that ease of use can lead to security by helping to avoid mis-use. At least on OpenJDK 6 Runtime.exec() is implemented using ProcessBuilder : public Process exec(String[] cmdarray, String[] envp, File dir) throws IOException { return new ProcessBuilder(cmdarray) .environment(envp) .directory(dir) .start(); } 来源: https://stackoverflow.com/questions/5886829/processbuilder-vs-runtime-exec

ProcessBuilder environment variable in java

北城以北 提交于 2019-11-29 04:11:42
I'm trying to add a environment variable for a ProcessBuilder object but then when I call on that new variable in the ProcessBuilder I get an error. this is how I build the Process public class OTU { public static void main(String[] args) throws Exception { ProcessBuilder pb = new ProcessBuilder(); Map<String, String> env = pb.environment(); //set environment variable u env.put("u", "util/"); pb.command("echo $u"); Process p = pb.start(); String output = loadStream(p.getInputStream()); String error = loadStream(p.getErrorStream()); int rc = p.waitFor(); System.out.println("Process ended with