runtime.exec

Fetch and store output from a subprocess in Java

☆樱花仙子☆ 提交于 2019-12-05 04:43:27
问题 I'm working on something that requires me to start to subprocess(command prompt) and execute some commands on it. I need to fetch the output from the subprocess and store it in a file or String. here's what I have done so far, and it doesn't work: public static void main(String args[]) { try { Runtime RT = Runtime.getRuntime(); String command = "cmd /c start javap java.lang.String"; File file = new File("write.txt"); Writer output = new BufferedWriter(new FileWriter(file)); BufferedReader br

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

混江龙づ霸主 提交于 2019-12-04 20:23:44
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.append(" -alias myProduct"); command.append(" -keypass " + "testtest"); command.append(" -keystore " + f

Using Runtime.getRuntime().exec in eclipse

北慕城南 提交于 2019-12-04 17:10:40
I'm using Runtime.getRuntime().exec in eclipse to run another java program from the current program. I've used the following code. InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); System.out.println("Enter the class name"); String s=br.readLine(); String str="XYZ"; String[] cmd = {"java","-cp", "C:/Users/..../workspace/Testing/bin",s,str}; Process pro=Runtime.getRuntime().exec(cmd); I'm also passing a string "XYZ" to that program. That program just accepts the string and displays Your string is XYZ But by using the line String[] cmd = {"java","

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

南笙酒味 提交于 2019-12-04 15:46:40
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.out.println("Commands executed successfully"); When I run this program I get "Commands executed

Get Java Runtime Process running in background

孤者浪人 提交于 2019-12-04 15:40:26
I'm writing a java application where I require to run a process in background throughout the lifetime of the running application. Here's what I have: Runtime.getRuntime().exec("..(this works ok).."); Process p = Runtime.getRuntime().exec("..(this works ok).."); InputStream is = p.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); So, basically I print out every br.readLine() . The thing that I'm not sure about is how to implement this code in my application because wherever I put it (with Runnable), it blocks other code from

Android- Error during executing Runtime.getRuntime().exec() - Environment Null -ffmpeg

混江龙づ霸主 提交于 2019-12-04 15:17:13
I have compiled ffmpeg library on ubuntu 11.10 and ported compiled files on android. After compiling i got libffmpeg.so successfully. It gets loaded on android successfully. I am doing it on ubuntu 11.10 eclipse android emulator. I have created a small test application which act as command prompt which accepts command from user and displays result. (testing ffmpeg commands) When i run simple commands like "ls", "ls -l" it works perfectly. but when i simply type " cd mnt " or " ffmpeg " as command and try to run it. I got Warnings in Logcat saying that 08-26 16:44:52.553: W/System.err(5961):

Java - Run Excel using runtime.getRuntime().exec

血红的双手。 提交于 2019-12-04 14:54:39
try { Runtime.getRuntime().exec("excel C:\\file.xls"); } catch (IOException ex) { System.out.println(ex); } Doesn't work. I have to put the full path of excel.exe in order to work. How can I make it generic (For any Excel Folders/Versions)? When I run the same line from OS with Windows Run (Start --> Run) it works. Is there a code in Java to simulate Windows' Run command? Why don't you try with the Desktop class (api doc here ) introduced in JDK6 that has the method public void open(File file) throws IOException which is documented as what you want to do: Launches the associated application to

Unable to execute java program from jsp using Runtime.getRuntime().exec

半世苍凉 提交于 2019-12-04 06:25:21
问题 I am trying to run a jar file through jsp. I use the command Runtime.getRuntime().exec("java -jar file.jar"); I get the error Unable to access jarfile file.jar when I print the error stream. I tried running with the classpath set to the current directory as Runtime.getRuntime().exec("java -cp . -jar file.jar"); but still get the same error. I also tried giving the entire path to the jar file. When I do this, the jsp file hangs after execuing the exec statement. This is the line I use in

How to programatically check if a software utility is installed on ubuntu using Java

不问归期 提交于 2019-12-04 06:06:22
问题 I am working on a Java Project for my own learning, what i have made is a class which can both read and write to external process using Runtime.getRuntime().exec(cmd); Now i was wondering is there any special way of checking if a particular software/tool is installed on the system. Like i use sshpass utility to remotely login to other machines, and if it is not there already i would like to install it using my program. But for this how should i go about checking if it exists there or not? The

open PDF File with parameters

偶尔善良 提交于 2019-12-04 05:58:24
问题 i am working on a java based tool, which should search for PDF files on selected directories and which should search for special words/sentences in this PDF files. After that a JList shows the files which fits and with a double-click on one of these entries the PDF Reader (Adobe Reader) should open this file directly on the page where the word/sentence appeares. I tried two different things. Runtime.exec: try{ Runtime.getRuntime().exec("rundll32" + " " + "url.dll,FileProtocolHandler /A page=4