runtime.exec

Problems killing child process invoked in Java

丶灬走出姿态 提交于 2019-12-07 18:07:10
问题 From within my program, I invoke a Linux process, read the output from that process, process it and then sleep until the next iteration. The problem I'm having is that the process I call doesn't always die, even when I do a childProcess.destroy() . Here's the code: while(true) { Process childProcess = Runtime.getRuntime().exec("./getData"); InputStream input = childProcess.getInputStream(); BufferedReader inPipe = new BufferedReader(new InputStreamReader(input)); while((lineRead = inPipe

Using quotes and double quotes in Java Runtime.getRuntime().exec(…)

ⅰ亾dé卋堺 提交于 2019-12-07 06:44:36
问题 I am trying to start a Lisp Image from Java in Mac OSX. Using the Image from my console I type the following: lisp_image --eval '(package::method "some_argument")' everything runs fine. In Java I have the problem to pass the quotes and double quotes using the Runtime.getRuntime().exec("lisp_image --eval '(package::method \"some_argument\")'"). I also tried to use : Runtime.getRuntime().exec(new String[] {"lisp_image", "--eval ", "\'(package::method ", "--eval ", "\"", "some_argument", "\")",

Keytool usage with Runtime.getRuntime().exec() under Linux

≯℡__Kan透↙ 提交于 2019-12-06 12:29:55
问题 I'd like to call the java keytool during runtime execution providing dynamic arguments. Here's what is working under Windows, but not under Linux (Ubuntu) same Java 1.6.0: File f = new File("mykey.jks"); StringBuilder command = new StringBuilder(); command.append(System.getProperty("java.home") + System.getProperty("file.separator") + "bin" + System.getProperty("file.separator") + "keytool"); command.append(" -genkey"); command.append(" -dname \"cn=foo,ou=bar,o=company,c=CH\""); command

Java Runtime Exec for VBA script with arguments

放肆的年华 提交于 2019-12-06 12:01:38
I am trying to use Runtime exec() to run a vba script with arguements. I am having trouble passing in the args. I think I need to use the String[] overloaded method for exec. Currently this works: String command = "cmd /c \"\\concat2.vbs\"" Process p = Runtime.getRuntime().exec(command); But I want to run that with arguments and if I do this String command = "cmd /c \"\\concat2.vbs\" " + arg1 + " " + arg2 where arg1 and arg2 are strings my program doesnt run (status = 1) I think I need to use the String[] overloaded method for exec Exactly! Change your command to be a String array. The array

Problem with starting OpenOffice service (soffice) from Java (command working in commandline, but not from Java)

泪湿孤枕 提交于 2019-12-06 11:04:49
问题 I want to exceute a simple command which works from the shell but doesn't work from Java. This is the command I want to execute, which works fine: soffice -headless "-accept=socket,host=localhost,port=8100;urp;" This is the code I am excecuting from Java trying to run this command: String[] commands = new String[] {"soffice","-headless","\"-accept=socket,host=localhost,port=8100;urp;\""}; Process process = Runtime.getRuntime().exec(commands) int code = process.waitFor(); if(code == 0) System

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

Cannot get the getInputStream from Runtime.getRunTime.exec()

血红的双手。 提交于 2019-12-06 05:27:30
问题 public class LinuxInteractor { public static String executeCommand(String command) { System.out.println("Linux command: " + command); try { Process p = Runtime.getRuntime().exec(command); p.waitFor(); BufferedReader bf=new BufferedReader(new InputStreamReader( p.getInputStream())); String str=bf.readLine(); System.out.println("inputStream is::"+str); while( (str=bf.readLine()) != null) { System.out.println("input stream is::"+str); } System.out.println("process started"); } catch (Exception e

Java Runtime.getRuntime().exec() with quotes

你说的曾经没有我的故事 提交于 2019-12-06 00:37:38
问题 I am trying to run ffmpeg via the exec call on linux. However I have to use quotes in the command (ffmpeg requires it). I've been looking through the java doc for processbuilder and exec and questions on stackoverflow but I can't seem to find a solution. I need to run ffmpeg -i "rtmp://127.0.0.1/vod/sample start=1500 stop=24000" -re -vcodec copy -acodec copy -f flv rtmp://127.0.0.1/live/qltv I need to insert quotes into the below argument string. Note simply adding single or double quotes

Name of the Operating System in java (not “os.name”)

随声附和 提交于 2019-12-05 18:18:15
I'd like to know how to get hold of the kind of Operating System the jvm is running on. It has to be "secure" as well, so System.getProperty("os.name") is not really an option because it can be trivially circumvented with the -D directive. By "secure" I mean nontrivial to circumvent. It's for a desktop application. The user could always deobfuscate, decompile, edit and recompile the code, but that is significantly harder than passing -D to the jvm. We want to make tinkering nontrivial, not impossible (since that can't be done). First, it's impossible to protect code from being manipulated

Runtime.getRuntime().exec(), executing Java class

て烟熏妆下的殇ゞ 提交于 2019-12-05 16:41:29
I am executing Java class from inside my application. proc = Runtime.getRuntime().exec("java Test"); How can I recognize whether Test executed successfully or not (i.e. no exceptions)? Redirecting output / error: proc = Runtime.getRuntime().exec(new String[] { "java", mclass, ">NUL 2>test.txt" }); From cmd : java Main >NUL 2>test.txt khachik process.waitFor(); int exitCode = process.exitValue(); if(exitCode == 0) { // success } else { // failed } This works, if the Test is designed properly and returns appropriate exit codes (generally, >0 if something went wrong). If you want to get Test s