For vhdl beautifier, I am using Emacs and in Linux I am using the command in terminal:
emacs --batch --visit=FILENAME.vhd --funcall=vhdl-beautify-buffer --funcall=save-buffer
And this working fine, however when trying to call this command within a java file as below not working! :
String command = "emacs --batch --visit=FILENAME.vhd --funcall=vhdl-beautify-buffer --funcall=save-buffer";
Process p = Runtime.getRuntime().exec(command);
what can be causes for that?
Related
I'm trying to open a PDF file in Linux with the xdg-open command in java.
String[] command = {"xdg-open","\""+path+"\""}
Process p = Runtime.getRuntime().exec(command,null);
p.waitFor();
When I run the code in terminal nothing happens even tho if I type it in terminal:
xdg-open path
it opens the PDF.
Any ideas whats wrong?
You should not escape the path: if the program was called, it was with an invalid path ("path" and not path).
String[] command = {"xdg-open", path}
The Runtime.getRuntime().exec(command,null); will use ProcessBuilder internally which, in the case of Linux, should invoke the system command execve.
I am trying to open a vi editor using Java code in an linux env (the java code is executed via shell script). The editor should open in foreground & become active terminal, while the java is should be running at Background.
I tried using both commands using :-
String []command = {"xterm", "vi", "/home/user/test.txt"};
Process pr = Runtime.getRuntime().exec(command);
Process p = new ProcessBuilder("vi", "/home/user/test35.txt").start();
In one of the above code, if check the ps -ef | grep vi, I am able to the process, but its running at background. I want to run it in foreground as an active terminal as user for his type the text into the editor. While the java will be running at the background.
Any suggestion or snippet's.
I have referred this Open VIM with Java application , but still in vain.
If you want to create a new xterm and execute a command in that terminal, you need to pass the command with -e. Try this:
ProcessBuilder pb = new ProcessBuilder("xterm", "-e", "vi", "/home/user/test.txt");
The debug steps I did was I tried opening a terminal via command & use the same command in the Java code. Issue observed that I need to set DISPLAY=:0. if I am running via root user , for other user export DISPLAY was not needed
String []command = {"/usr/bin/xterm","-e", "vi", "/home/hscpe/test.txt"};
Process pr = Runtime.getRuntime().exec(command);
Since I am running the java code via shell script I will be adding export in the shell script i.e export DISPLAY=:0. Now will try to make the editor as editable (Will stimulate by pressing I , i.e Insert by java robot).
I referred here & here
I installed ffmpeg on mac through brew install. When i run ffmpeg command from terminal, it is running fine. But when i create a program in java and execute command like
Runtime.getRuntime().exec("ffmpeg");
It is throwing IOException
Cannot run program "ffmpeg":error=2, No such file or directory.
Any idea how to resolve it?
Try using the below code
String[] command = new String[]{"/bin/bash","-c","ffmpeg -version"};
Process p = Runtime.getRuntime().exec(command);
I am working on Windows and I have downloaded cygwin.
I want to launch the cygwin terminal from a java program but I can't find the command so I can launch the terminal and then write line command into it.
When I go to the cygwin Terminal icon parameters, I can see this :
target: C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -
But when I use this to launch the terminal on my program:
ProcessBuilder pb = new ProcessBuilder("C:\\cygwin64\\bin\\mintty.exe", "cd Documents");
I have a shell that opens wit this :
cd Documents: No such file or directory
I think that my problem is that I launch the wrong cygwin terminal but I can't find where is the right Cygwin terminal.
Does anyone knows where is the right cygwin terminal so I can write line commands in my java program and the temrinal will understand them ?
I'm trying to run this command:
"C:\arduino\arduino --upload --board arduino:avr:nano --port COM3 -v ..\config\config.ino"
It works from my command line. It takes just a few seconds to run & finish.
The problem comes when I try to execute it from Java with:
String cmd = "C:\arduino\arduino --upload --board arduino:avr:nano --port COM3 -v ..\config\config.ino"
Process p = Runtime.getRuntime().exec(cmd);
It takes a minute to execute and ends with:
Launch 4j: an error occurred while starting the application
I've tried with ProcessBuilder too. I've also tried saving the command to a batch file and then running the batch file from Java...but I just got the same result.
EDIT:
If I run the batch file from command line it works too. As I said if I run it from Java, it doesn't.
I've realized that if I run the batch file from another batch file it doesn't work neither.
Maybe there is not a problem at all with Java, but with Arduino IDE.
EDIT 2:
Adding "start" parameter before the command and saving it to a batch file seems to work. Then you just run the batch from java.
Something like this:
arduino.bat
"start C:\arduino\arduino --upload --board arduino:avr:nano --port COM3 -v ..\config\config.ino"
Java code
String s = "PATH TO ARDUINO.BAT"
Process p = null;
ProcessBuilder pb = new ProcessBuilder(s + "arduino.bat");
pb.directory(new File(s));
p = pb.start();
I think the issue is with the relative path at -v argument. Use full path or set
actual working directory with ProcessBuilder.