processbuilder

Java Runtime OR Processbuilder OR Other

て烟熏妆下的殇ゞ 提交于 2019-12-25 14:10:20
问题 I'd like to know what the best alternative is for running command line executables from Java. The Target platforms for the commands are Windows 7(+) and Unix/Linux. I have a class that currently uses Runtime.exec() along with the enhancements from the JavaWorld StreamGobbler article. It works about 90% of the time on both Windows and Unix. The other 10% of the time I need to extend the class and then fiddle with putting cmd.exe of /bin/sh in front of the command. I've also had to fiddle

Java Runtime OR Processbuilder OR Other

江枫思渺然 提交于 2019-12-25 14:09:15
问题 I'd like to know what the best alternative is for running command line executables from Java. The Target platforms for the commands are Windows 7(+) and Unix/Linux. I have a class that currently uses Runtime.exec() along with the enhancements from the JavaWorld StreamGobbler article. It works about 90% of the time on both Windows and Unix. The other 10% of the time I need to extend the class and then fiddle with putting cmd.exe of /bin/sh in front of the command. I've also had to fiddle

Trouble with ProcessBuilder

吃可爱长大的小学妹 提交于 2019-12-25 09:00:10
问题 Following code opens status very fine in notepad: import java.util.*; class test { public static void main(String args[]) { try{ ProcessBuilder pb=new ProcessBuilder("notepad","F:/status"); pb.start(); }catch(Exception e) { System.out.println(e); } } } Following code does'not play the song: import java.util.*; class test { public static void main(String args[]) { try{ ProcessBuilder pb=new ProcessBuilder("C:/Program Files (x86)/VideoLAN/VLC/vlc","D:/02 Tu Jaane Na"); pb.start(); }catch

Complex Imagemagick command via ProcessBuilder

可紊 提交于 2019-12-25 08:37:59
问题 I'm trying to get following ImageMagick command working with the Java ProcessBuilder: convert.exe image.png `( `+clone -alpha extract mask.png -compose Darken -composite `) -compose CopyOpacity -composite out.png The file paths (source image, mask image and destination image) are configurable. If I enter the command in PowerShell or Windwos Cmd it is working as expected. When I'm trying to execute the same command via Java ProcessBuilder, it fails. Here is my last code: File srcFile = new

Why can't I re-execute a Java program from within an Exception block? [duplicate]

时间秒杀一切 提交于 2019-12-25 04:52:11
问题 This question already has answers here : Capture SIGINT in Java (3 answers) Closed 4 years ago . I'm trying to run the following Java code which is supposed to automatically restart itself when I kill it via CTRL + C on windows command-line : import java.net.*; import java.io.*; public class LineRunner extends Thread { public static void main(String[] args) throws InterruptedException, IOException{ try { for (int i = 0; i<10000000; i++) { Thread.sleep(200); System.out.print("hithe"); } }

JAVA - continues application run

半腔热情 提交于 2019-12-25 03:32:28
问题 I have the following code. public static void main(String args[]){ ProcessBuilder pb = new ProcessBuilder("java","-xmx768m","DesDatMain","anArgument"); pb.directory(new File(".")); try{ Process process = pb.start(); } catch(IOException e){ e.printStackTrace(); } SwingUtilities.invokeLater(new Runnable(){public void run(){new JFrame();}}); } If I run it in “home” folder (containing source files etc.) it will continuously run one app by one app. The same result has executable jar. But if I move

Java ProcessBuilder and bash

不打扰是莪最后的温柔 提交于 2019-12-25 02:13:21
问题 I am trying to execute a bash script from Java with ProcessBuilder my code is : Process createUser = buildProcess( "/bin/su", "-c", "\"/opt/somedir/testdir/current/bin/psql", "--command", commandForUserCreation, /* "'select * from users'", */ "--dbname", "mydbname\"", "myuser" ); The problem is that I receive error: /bin/su: unrecognized option '--dbname' If I put echo in first place of my commands it prints correct command in bash and if I copy/paste this command it works! Please, help me to

Maximum length of string argument in java processbuilder

拥有回忆 提交于 2019-12-24 18:42:31
问题 I know there is a string limitation when we execute application from command line / terminal which depends on the OS. But if we use the Java ProcessBuilder to execute application, is there any maximum string length to be passed as argument in the java ProcessBuilder ? ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2"); Thanks 回答1: If you look at ProcessBuilder source code the process creation is delegated to a OS specific java.lang.ProcessImpl . For instance the Windows

Java ProcessBuilder

烈酒焚心 提交于 2019-12-24 14:17:23
问题 I'm having problems using ProcessBuilder to run a class in my project. My code: public class Main { public static void main(String[] args) { try { String pathToJar = Main.class.getProtectionDomain().getCodeSource() .getLocation().toURI().getPath(); ArrayList<String> params = new ArrayList<String>(); params.add("javaw"); params.add("-classpath"); params.add(pathToJar); params.add("Program"); ProcessBuilder pb = new ProcessBuilder(params); Process process = pb.start(); } catch (Exception e) { e

Java ProcessBuilder memory

北战南征 提交于 2019-12-24 10:36:51
问题 I was wondering if anybody knew with any certainty whether ProcessBuilder/Runtime.exec() executes inside the space of the JVM's memory or whether it uses completely separate system memory and somehow sends the output to Java. I could not find any documentation on the subject. I assume it is the former due to security issues and being able to read output, but I would like to make absolutely sure. 回答1: The new process runs outside the Java process that started it. Allocation of memory to the