runtime.exec

Shell (bash) brace expansion with Java's runtime.exec

让人想犯罪 __ 提交于 2019-12-02 07:09:35
问题 I'm trying to get an expansion command to work with runtime.exec, but the braces are being interpreted as literals rather than being expanded. Here's what I'm trying to do: String command = "mkdir -p Foldername{1,2,3}/InnerFolder"; Runtime.getRuntime().exec( new String[] { "sh", "-c", command } ); Unfortunately, that gives me a single folder in my current directory named "Foldername{1,2,3}" instead of "Foldername1", "Foldername2", and "Foldername3". Does anyone know of a way to prevent the

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

寵の児 提交于 2019-12-02 04:36:32
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) { e.printStackTrace(); } Runtime.exec Code - GWT Compile Error: Rebinding dir.ClientGinjector Checking

Execute spark-submit programmatically from java

旧街凉风 提交于 2019-12-02 04:33:33
I am trying to execute it via: Process process = Runtime.getRuntime().exec(spark_cmd); with no luck. The command ran via shell starts my application which succeeds. Running it via exec start a process which dies shortly after and does nothing. When I try process.waitFor(); it hangs and waits forever. Real magic begins when I try to read something from the process: InputStreamReader isr = new InputStreamReader(process.getErrorStream()); BufferedReader br = new BufferedReader(isr); To do so I start a thread that reads from the stream in a while loop: class ReadingThread extends Thread {

Using Java to do a WIndows command line command

一曲冷凌霜 提交于 2019-12-02 03:32:25
I am running the Java code from Directory A, and there is a myBat.bat file there too. I want to use Java to execute the bat file. The contents of the myBat.bat is : svn update C:\DirectoryB\file.txt I have already downloaded the Slik SVN Windows command line client. When i double click on the bat file, it svn updates the file correctly. But not when i run my Java code. Process p = Runtime.getRuntime().exec("cmd /C C:\\DirectoryA\\myBat.bat"); The test fails because it cannot find the file.txt that it was expecting. In order to really test the svn update, i have deleted the svn file in

Shell (bash) brace expansion with Java's runtime.exec

风格不统一 提交于 2019-12-02 00:24:17
I'm trying to get an expansion command to work with runtime.exec, but the braces are being interpreted as literals rather than being expanded. Here's what I'm trying to do: String command = "mkdir -p Foldername{1,2,3}/InnerFolder"; Runtime.getRuntime().exec( new String[] { "sh", "-c", command } ); Unfortunately, that gives me a single folder in my current directory named "Foldername{1,2,3}" instead of "Foldername1", "Foldername2", and "Foldername3". Does anyone know of a way to prevent the braces from being interpreted as literals? Mateusz You're trying to use Bash wildcards. They are

“Cannot run program” when using Runtime.exec with spaces in program filename

可紊 提交于 2019-12-01 22:58:25
I am using the below code to open the "sample.html' file. String filename = "C:/sample.html"; String browser = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"; Runtime rTime = Runtime.getRuntime(); Process pc = rTime.exec(browser + filename); pc.waitFor(); However, I am getting the below error. java.io.IOException: Cannot run program "C:/Program": CreateProcess error=2, The system cannot find the file specified Could someone please help me figure this. Thanks in advance. Runtime.exec(String) automatically splits the string at spaces, assuming the first token is the command name

External program blocks when run by Runtime exec

此生再无相见时 提交于 2019-12-01 21:51:10
I'm attempting to launch an instance of the VideoLAN program from within a java application. One of the ways I've tried to do this is shown here: Process p = Runtime.getRuntime().exec("\"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe\" \"http://www.dr.dk/Forms/Published/PlaylistGen.aspx?qid=1316859&odp=true\" :sout=#std{access=udp,mux=ts,dst=127.0.0.1:63928}"); If I execute the above command the vlc program will be launched, and will start a streaming operation (it goes through connect, buffering and then streaming phases). When the command is executed by Runtime exec (or ProcessBuilder start), the

External program blocks when run by Runtime exec

為{幸葍}努か 提交于 2019-12-01 21:48:14
问题 I'm attempting to launch an instance of the VideoLAN program from within a java application. One of the ways I've tried to do this is shown here: Process p = Runtime.getRuntime().exec("\"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe\" \"http://www.dr.dk/Forms/Published/PlaylistGen.aspx?qid=1316859&odp=true\" :sout=#std{access=udp,mux=ts,dst=127.0.0.1:63928}"); If I execute the above command the vlc program will be launched, and will start a streaming operation (it goes through connect, buffering

How to programmatically answer a call in Android 4.0.3?

拈花ヽ惹草 提交于 2019-12-01 15:02:53
So as the subject states I need to be able to answer a phone call programmatically in Android 4.0.3 on an HTC OneX. I have read several places that the MODIFY_PHONE_STATE permission has been revoked by Google so to do this task you need a work around. I have looked into two avenues so far: (1) Following Guy's post here and using a BroadcastReceiver (2) Using the following code to try and hit a key event through a shell command. final Runtime r = Runtime.getRuntime(); try { Process process = r.exec("input keyevent 5"); InputStream stream = process.getErrorStream(); log.v("Process Error Stream:

Parse out time portion from ping results in Java

独自空忆成欢 提交于 2019-12-01 08:11:17
问题 I managed to modify a program to ping peer computer and gets the ping counts. How can I parse out the time = ?ms from the ping count results, in real-time? Code: public static void main(String[] args) { String ip = "192.168.1.1 -n 10"; String pingResult = ""; String pingCmd = "ping " + ip; try{ Runtime r = Runtime.getRuntime(); Process p = r.exec(pingCmd); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String inputLine; while ((inputLine = in.readLine()) !=