runtime.exec

Calling GnuPG in Java via a Runtime Process to encrypt and decrypt files - Decrypt always hangs

白昼怎懂夜的黑 提交于 2019-12-04 03:28:42
问题 NOTE: Coming back to this later as I've been unable to find a working solution. Draining the input streams manually instead of using BufferedReaders doesn't seem to help as the inputStream.read() method permanently blocks the program. I placed the gpg call in a batch file, and called the batch file from Java to only get the same result. Once gpg is called with the decrypt option, the input stream seems to become inaccessible, blocking the entire program. I'll have to come back to this when I

How to get java getRuntime().exec() to run a command-line program with arguments?

Deadly 提交于 2019-12-03 12:21:48
问题 I've been trying to write a java program that uses the Runtime.getRuntime().exec() method to use the command-line to run an instance of the program "tesseract". Some background, Tesseract is a free open source program that is used to perform OCR (Optical Character Recognition) on pictures. It takes in a picture file and outputs a text document. It is a command-line program that uses this command to run (from within the command prompt shell) tesseract imageFilePath outFilePath [optional

The right way to kill a process in Java

ε祈祈猫儿з 提交于 2019-12-03 10:34:12
What's the best way to kill a process in Java ? Get the PID and then killing it with Runtime.exec() ? Use destroyForcibly() ? What's the difference between these two methods, and is there any others solutions ? Derlin If the process you want to kill has been started by your application Then you probably have a reference to it ( ProcessBuilder.start() or Runtime.exec() both return a reference). In this case, you can simply call p.destroy() . I think this is the cleanest way (but be careful: sub-processes started by p may stay alive, check http://bugs.sun.com/bugdatabase/view_bug.do?bug_id

What is the purpose of Process class in Java?

有些话、适合烂在心里 提交于 2019-12-03 06:25:04
Runtime objRuntime = Runtime.getRuntime(); String strBackupString = "mysqldump -u " + userName + " -p" + password + " " + dbName; Process objProcess = objRuntime.exec(strBackupString); This is used for backup of database. But what exactly happens? Can anybody make me explain, what is the purpose of Runtime and Process class? Is this class used to act as if we are typing command from command prompt? Then what should i pass to objRuntime.exec() if i want to open notepad? And is the command executed as soon as we call exec method? If yes, then what purpose does Process serve here? I really can't

How to get java getRuntime().exec() to run a command-line program with arguments?

浪子不回头ぞ 提交于 2019-12-03 02:55:33
I've been trying to write a java program that uses the Runtime.getRuntime().exec() method to use the command-line to run an instance of the program "tesseract". Some background, Tesseract is a free open source program that is used to perform OCR (Optical Character Recognition) on pictures. It takes in a picture file and outputs a text document. It is a command-line program that uses this command to run (from within the command prompt shell) tesseract imageFilePath outFilePath [optional arguments] example: tesseract "C:\Program Files (x86)\Tesseract-OCR\doc\eurotext.tif" "C:\Users\Dreadnought

Runtime.exec().waitFor() not actually waiting for

余生颓废 提交于 2019-12-03 02:34:56
I've got some code that uses Runtime.exec() to run an external .jar (built as an IzPack installer). If I run this external.jar from the command line like so: java -jar external.jar Then the command prompt does not return control until the application is finished. However, if I run external.jar from within some java class, using: Process p = Runtime.getRuntime().exec("java -jar external.jar"); int exitCode = p.waitFor(); System.out.println("Process p returned: " + exitCode); Then p returns almost instantly with a success code of 0 , despite external.jar having not yet completed execution (i've

Execute java file with Runtime.getRuntime().exec()

核能气质少年 提交于 2019-12-02 17:45:42
问题 This code will execute an external exe application. private void clientDataActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { Runtime.getRuntime().exec("C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe"); } catch(Exception e) { System.out.println(e.getMessage()); } } What if I want to execute external java file? Is it possible? For example like this command: Runtime.getRuntime().exec("cmd.exe /C start cd \"C:\Users\sg552\Desktop\ java testfile"); The

How to destroy all Processes from a Runtime at once?

↘锁芯ラ 提交于 2019-12-02 17:40:15
问题 So for example: Runtime rt = Runtime.getRuntime(); creates Runtime rt Process p1 = rt.exec("C:/Windows/System32/calc.exe"); creates Process p1 on Runtime rt . Then p1.destroy(); will destroy Process p1 . My question is: If I have more than one Process (e.g. p1 , p2 , and p3 ), how do I destroy them all at once, instead of having to destroy them one by one? 回答1: Keep a List<Process> of all your processes and destroy them in a loop. List<Process> processes = ... for(Process p : processes) { p

linux ulimit with java does not work properly

血红的双手。 提交于 2019-12-02 16:02:39
问题 I run code on linux ubuntu 17.10 public class TestExec { public static void main(String[] args) { try { Process p = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", "ulimit", "-n"}); BufferedReader in = new BufferedReader( new InputStreamReader(p.getInputStream())); String line = null; while ((line = in.readLine()) != null) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } } } this code returns "unlimited" but whenever I run command from terminal I get 1024

Calling an external application (i.e. Windows Calculator) in a GWT web application

风格不统一 提交于 2019-12-02 14:10:30
问题 I am trying to call an external windows application (i.e. calc.exe) when a user clicks on a button in a GWT web application. Is there a way on how to do it? Below are what I have already tried so far: 1.) Tried Runtime.exec and ProcessBuilder but I end up having a GWT compile error Runtime.exec Code: Process winCalc; try { winCalc = Runtime.getRuntime().exec("\"C:/Windows/System32/calc.exe\""); winCalc.waitFor(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e)