runtime.exec

Trigger a spark job whenever an event occurs

元气小坏坏 提交于 2019-12-11 02:12:21
问题 I have a spark application which should run whenever it receives a kafka message on a topic. I won't be receiving more than 5-6 messages a day so I don't want to take spark streaming approach. Instead I tried to submit the application using SparkLauncher but I don't like the approach as I have to set spark and Java classpath programmatically within my code along with all the necessary spark properties like executor cores, executor memory etc. How do I trigger the spark application to run from

Reboot programmatically Android Things

眉间皱痕 提交于 2019-12-10 23:17:56
问题 I want to use this code in order to reboot my RPI3 running Android Things : public static void Reboot() { try { Process proc = Runtime.getRuntime().exec(new String[]{"su", "-c", "reboot"}); proc.waitFor(); } catch (Exception ex) { ex.printStackTrace(); } } I get the following error: java.io.IOException: Cannot run program "su": error=13, Permission denied I add to the manifest all the permission <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name=

Runtime.exec never returns when reading system.in

眉间皱痕 提交于 2019-12-10 22:55:54
问题 Here is my sample code, I want to handle the command from standard input while running a new sub process. However, the exec method never returns if I read the system.in. The command in the exec() is very simple and has nothing to do with the stdin. I'm wondering about is there any way to solve this? How can I start a new sub process while start another thread reading stdin? public static void main(String[] args){ new Thread(new Runnable(){ public void run(){ BufferedReader reader = new

Runtime.getRuntime().exec(String[]) safety

ぃ、小莉子 提交于 2019-12-10 19:46:01
问题 I'm using Runtime.getRuntime().exec(String[]) to run processes where some of the elements of the String array are defined by the user. Is this safe? Or will it allow to inject code into the terminal? If it isn't safe what can i do to avoid code injection? (it has to be platform independent) 回答1: As i mentioned in a comment on another answer (might as well add my own answer), this should be safe as long as you control the first argument. 回答2: Generally this isn't safe since it should be

How to Exit a Process (.exec()) if the External Program hangs

吃可爱长大的小学妹 提交于 2019-12-10 19:17:44
问题 Let me explain my software. What my software simply does is that it creates 10 threads and assigns a number of tasks to each thread. Each thread then creates a Runtime Process that will start a cmd batch file which in turn will start a program that will telnet to a device (I have about 200 of them) to poll its configuration. Here is the code for my process creation: Process p1 = java.lang.Runtime.getRuntime().exec("cmd /c start /b /wait " + batchFile); int returnVal = p1.waitFor(); batchFile

Compiling and executing Java code using Runtime#exec()

霸气de小男生 提交于 2019-12-10 16:53:40
问题 import java.io.*; public class Auto { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { try { Runtime.getRuntime().exec("javac C:/HelloWorld.java"); Runtime.getRuntime().exec("java C:/HelloWorld > C:/out.txt"); System.out.println("END"); } catch (IOException e) { e.printStackTrace(); } } } This program is able to compile the 'HelloWorld.java' file, but not execute it(HelloWorld). Could anyone please suggest me how to make it work? Thanks in

Java Runtime exec throws no such file or permission denied

依然范特西╮ 提交于 2019-12-10 14:13:12
问题 My program is running on ubuntu 10.04 ,and here is the code : Process process=Runtime.getRuntime().exec("ls",null,null); it throw an exception of : Cannot run program "ls": java.io.IOException: error=2, No such file or directory, and i tried to change "ls " to "chmod" ,"pwd" ,i found no one shell command work, all came to the same problem .(I also tried "/bin/sh -c ls") and then i change the code to : Process process=Runtime.getRuntime().exec("/bin/ls",null,null); it throw an exception of :

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

狂风中的少年 提交于 2019-12-10 09:35:52
问题 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

What is the purpose of Process class in Java?

孤街醉人 提交于 2019-12-09 05:30:33
问题 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

java runtime.exec cmd /c parsing quoted arguments

二次信任 提交于 2019-12-08 19:38:34
I'm trying to run runtime.exec(String[],null, new File(directory)) with the first two arguments being "cmd" and "/c". I'm trying to specify the version of java for my tomcat to run. It appears that the cmd /c arguments are causing runtime.exec to parse all of the arguments by space delineation or probably more appropriately cmd is parsing each argument out. So, cmd /c .\bin\Tomcat7.exe //US//Tomcat7 --Jvm="C:\Program Files\Apache Tomcat 7\jre\bin\server\jvm.dll" is getting the jvm argument broken into arguments "C:\Program", "Files\Apache","Tomcat..... which is causing to not be able to