runtime.exec

Trouble with ProcessBuilder

吃可爱长大的小学妹 提交于 2019-12-25 09:00:10
问题 Following code opens status very fine in notepad: import java.util.*; class test { public static void main(String args[]) { try{ ProcessBuilder pb=new ProcessBuilder("notepad","F:/status"); pb.start(); }catch(Exception e) { System.out.println(e); } } } Following code does'not play the song: import java.util.*; class test { public static void main(String args[]) { try{ ProcessBuilder pb=new ProcessBuilder("C:/Program Files (x86)/VideoLAN/VLC/vlc","D:/02 Tu Jaane Na"); pb.start(); }catch

Alternative to java.lang.Runtime.exec() that can execute command lines as a single string?

我怕爱的太早我们不能终老 提交于 2019-12-25 07:45:16
问题 I am calling java.lang.Runtime.exec(...) but this seems to accept the command lines as an array and I want to use a single string. How can I do the same using a single string? 回答1: From the linked Javadocs: envp - array of strings, each element of which has environment variable settings in the format name=value , or null if the subprocess should inherit the environment of the current process. So just pass in null for the second parameter, and the environment will be inhereted. 回答2: If you

Java exec can't run program, error = 2

血红的双手。 提交于 2019-12-25 01:12:37
问题 I'm trying to run R.exe from a Java application with Java exec. R is in the Environment Variables and if I execute it from cmd with "R" command it works. If I execute an example instruction in Java and try to open notepad it works: Runtime rt = Runtime.getRuntime(); Process p = rt.exec("notepad"); But when I try to open R with this instruction: Process p = rt.exec("R"); it gives me this kind of error: java.io.IOException: Cannot run program "R": CreateProcess error=2 what could be? why cant I

Minimize all other applications excluding my own program

末鹿安然 提交于 2019-12-24 13:22:36
问题 I am trying to minimize all running applications in Windows when running my own program. I am using the following code, but it's minimizing the all windows including my program. Is there any way that I can minimize the applications excluding my program? My code is following: try { Runtime.getRuntime().exec( new String[]{ "cmd.exe", "/c", "\"" + System.getenv("APPDATA") + "\\Microsoft\\Internet Explorer\\Quick Launch\\Show Desktop.scf\""}); } catch (Exception ex) { } 回答1: Why don't you use JNA

exec command in java

时光总嘲笑我的痴心妄想 提交于 2019-12-24 07:58:47
问题 If i am using following command in java: Process ps = Runtime.getRuntime().exec("some .exe file of VB"); How do I know that the particular .exe has done its job eg: it executed successfully. How do i know that it has some error or just completed half task in java. How should I design my program in java to know or Is there any way to tell java from VB. Any help is appreciated. 回答1: I would assume that you could look at the exit status of the program: ps.exitValue() or you could read the stdout

Runtime exec and a custom built RTF editor

ⅰ亾dé卋堺 提交于 2019-12-24 07:01:28
问题 I have a class that manages the creation of RTF documents and a method in that class that calls the RTF editor with a XML file for display. All but one user can access this editor without any issues. This one user consistently runs into an issue where their application just hangs. There are no errors in any logs. Normally this kind of problem is easily identified, reproduced and corrected, however, I can't for the life of my reproduce it so my attempts at debugging are failing. Basically the

in x64 Windows is there a way to run a Runtime.exec() process avoiding 'Registry redirection'

馋奶兔 提交于 2019-12-24 03:49:09
问题 Our app runs in jvm 32 bit, even when in windows x64. Now, at some point, I need to access some registry values, for example HKEY_LOCAL_MACHINE/SOFTWARE/mycomp. I do this by executing cmd /C reg query HKEY_LOCAL_MACHINE\SOFTWARE\mycop from Runtime.exec() and parsing the output. This works fine when running on windows 32b, the problem is when on x64, I cannot find the key, as the shell I run is a 32 bit process, and due to Registry Redirection I would get the key if it was on HKEY_LOCAL

Create new process with Runtime.getRuntime() in Android

做~自己de王妃 提交于 2019-12-24 03:42:08
问题 After searching the web about a problem I have I found that answer. in brief, I need to spawn a new process from an Android application, and run a simple C program. I've created simple C program, like the next one: int main() { printf("This is the message before sleep() function\n"); while(1){ Sleep(1000); } printf("This is the message after 1 second"); return 0; } Iv'e complied the C program with Cygwin with the next command (gcc myProgram.c -o myProgram). Iv'e put that file in the assest

Create new process with Runtime.getRuntime() in Android

白昼怎懂夜的黑 提交于 2019-12-24 03:42:03
问题 After searching the web about a problem I have I found that answer. in brief, I need to spawn a new process from an Android application, and run a simple C program. I've created simple C program, like the next one: int main() { printf("This is the message before sleep() function\n"); while(1){ Sleep(1000); } printf("This is the message after 1 second"); return 0; } Iv'e complied the C program with Cygwin with the next command (gcc myProgram.c -o myProgram). Iv'e put that file in the assest

java processbuilder windows command wildcard

家住魔仙堡 提交于 2019-12-24 02:32:05
问题 I want to invoke a Windows command from Java. Using the following line works fine: ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/C", "find \"searchstr\" C://Workspace//inputFile.txt"); But I want to find the string in all text files under that location, tried it this way, ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/C", "find \"searchstr\" C://Workspace//*.txt"); But it does not work and there is no output in the Java console. What's the solution? 回答1: It looks like find is