runtime.exec

Java Runtime command line Process

痴心易碎 提交于 2020-01-14 14:55:09
问题 I have a class with the following code: Process process = null; try { process = Runtime.getRuntime().exec("gs -version"); System.out.println(process.toString()); } catch (Exception e1) { e1.printStackTrace(); } finally { process.destroy(); } I can run "gs -version" on my command line and get: GPL Ghostscript 8.71 (2010-02-10) Copyright (C) 2010 Artifex Software, Inc. All rights reserved. So I know I have the path at least set somewhere. I can run that class from command line and it works. But

Java Runtime command line Process

那年仲夏 提交于 2020-01-14 14:55:08
问题 I have a class with the following code: Process process = null; try { process = Runtime.getRuntime().exec("gs -version"); System.out.println(process.toString()); } catch (Exception e1) { e1.printStackTrace(); } finally { process.destroy(); } I can run "gs -version" on my command line and get: GPL Ghostscript 8.71 (2010-02-10) Copyright (C) 2010 Artifex Software, Inc. All rights reserved. So I know I have the path at least set somewhere. I can run that class from command line and it works. But

How To Run Mac OS Terminal Commands From Java (Using Runtime?)

此生再无相见时 提交于 2020-01-11 05:40:09
问题 I've been looking up ways to run external programs using Java's runtime. This works fine, for instance: String[] cmd = {"mkdir", "test"}; Runtime.getRuntime().exec(cmd); Creates a new directory as you would expect. Now, from a bash window in Mac I can write this: love testgame To run the 'Love' game engine on a folder called testgame. Now, the reason this works is because I've aliased 'love' to call the love executable. I have a feeling that this is the reason that the following does not work

Ping function returns that all pinged IP addresses is reachable

走远了吗. 提交于 2020-01-07 04:45:08
问题 I am tring to ping IP addresses from 192.168.1.1 to 192.168.1.254. First I was using I InetAddress class but it was bugged and some IPs where not reachable even if they are. After that I tried this method and it worked very well for single ping IP but when I put it inside for-loop all pinged IPs where reachable... Can you guys tell me what's wrong here? CODE: public class Main { public static void main(String[] args) { String ip="192.168.1."; try { for(int i=0;i<=254;i++){ String ip2=ip+i;

Java Runtime exec() behavior

时光毁灭记忆、已成空白 提交于 2020-01-06 12:46:08
问题 I am attempting to programmatically generate javadocs via an instance of Runtime through the exec() method by passing in the commands necessary to generate javadocs. First of all I am unfamiliar with creating javadocs via the command line and second I am unfamiliar with the exec() method from Runtime . As a test I was able to execute executables compiled from C# classes through the exec() command but was not able to do so with executables compiled from C++ classes, what is causing this

Add space in adb command

给你一囗甜甜゛ 提交于 2020-01-06 06:34:33
问题 I want to execute "adb" command using Java. I tried out as follow: Process p = Runtime.getRuntime().exec(new String[]{"cmd","/c","adb devices"}); But, I get following error p.getErrorStream() : 'adb' is not recognized as an internal or external command,operable program or batch file. Is there any problem of space between "adb devices"? How to add space in command? 回答1: The problem is not the space, but the fact that adb is not found (because it's not on the path). Do one of those two things:

Add space in adb command

丶灬走出姿态 提交于 2020-01-06 06:34:05
问题 I want to execute "adb" command using Java. I tried out as follow: Process p = Runtime.getRuntime().exec(new String[]{"cmd","/c","adb devices"}); But, I get following error p.getErrorStream() : 'adb' is not recognized as an internal or external command,operable program or batch file. Is there any problem of space between "adb devices"? How to add space in command? 回答1: The problem is not the space, but the fact that adb is not found (because it's not on the path). Do one of those two things:

run class file as separate process from java code

不问归期 提交于 2020-01-05 08:11:41
问题 public static void main(String args[]) throws IOException { Process p = Runtime.getRuntime().exec("java E:/workspace/JNIProgram/src/JNIProgram.class"); } so I have this code and am trying to run the JNIProgram.class file however the program gets terminated instantly without doing its job (which is to create a new txt file and write to it) So what am I doing wrong 回答1: The java command expects a Java class name , not a filename. So the command java E:/workspace/JNIProgram/src/JNIProgram.class

run class file as separate process from java code

ぐ巨炮叔叔 提交于 2020-01-05 08:10:05
问题 public static void main(String args[]) throws IOException { Process p = Runtime.getRuntime().exec("java E:/workspace/JNIProgram/src/JNIProgram.class"); } so I have this code and am trying to run the JNIProgram.class file however the program gets terminated instantly without doing its job (which is to create a new txt file and write to it) So what am I doing wrong 回答1: The java command expects a Java class name , not a filename. So the command java E:/workspace/JNIProgram/src/JNIProgram.class

How to execute cmd command in Java class?

久未见 提交于 2020-01-05 07:17:27
问题 I want to call cmd command in java code. I say: String str ="C:/uploaded_files/111.txt"; Process process = Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c",str}); System.out.println(str); And dont get 111.txt . Its strange because when this code was in jsp all works fine. What can be wrong? 回答1: what's the problem with this code. It's perfectly working. opens and shows content of the file 111.txt try { String str ="C:/uploaded_files/111.txt"; Process process = Runtime.getRuntime().exec