Lauching Cygwin terminal from a JAVA program - java

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 ?

Related

Opening a PDF in java using Linux Terminal

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.

cmd windows path and environment variables unrecognized in Java Command Prompt

I am trying to execute the following
on the command line via the java runtime environment.
Runtime rt = Runtime.getRuntime();
String runtime = "cmd /c start cmd.exe /k \"cd /d C:\\Users\\User\\Documents\\ & python book.py \" "
rt.exec(runtime);
When running the command prompt directly, i.e. python book.py (assuming that I have already changed the location to the correct directory), python runs fine without any issues.
However, when done through java, the command prompt window looks different,
with C:\WINDOWS\system32\cmd.exe instead of displaying Command Prompt.
The above java runtime also gives me 'python' is not recognized as an internal or external command, operable program or batch file. (Whereas the normal command prompt the runs python perfectly fine)
How would I go about including my path and environment variables such that python, or any other path/environment variable, is recognized when I run the command prompt from java?
This may sound naiive but apparently, the solution was to restart the computer. I guess the PATH variables in the command prompt that was run JAVA weren't synchronized like in the other instances of running the command prompt directly.

Able to run programme in command promt but not through PHP system/exec command

I can run one program in my shell (Linux), but executing the same command on the same PC with PHP (using system or exec commands) does not work.
I can execute simple commands using system command in PHP (like ls or which Java).
I changed the permission of particular folder/program, and used whole path for my files and program.
system("/usr/bin/java -jar /pathforprogram/programe.jar -convert /pathtforinput/inputfile.txt -xtg outputfile.txt >optional.txt");
What can be the reason for this?

Execute command in a separate cmd or terminal

It is possible to execute external commands in java at run time.
However, what I am looking for is to actually open cmd or terminal and show that executing external command on screen.
I tried to execute a jar console application as java -jar jartool arguments, it works both on Windows and Ubuntu. The only problem is that, this does not open cmd or terminal separately. it runs the command in background.
We can use either ProcessBuilder and the start process or simply Runtime.getRuntime().exec.
I need to forcefully open the cmd or terminal. Java is configured to show console on windows but still no luck.
Any idea why this is happening or what should I do to force it to open cmd or terminal independent of current cmd or terminal.

how to run shell script in java using Cygwin

From a long time i am struggling for with this program. I am having a shell script which accepts parameters as version number and path for the files. then that script creates Zip file with the name of version number congaing all file files to the folder.
I have installed Cygwin on following path D:/cygwin. I am coping required files to same location where cygwin is installed D:\cygwin\bin
Command
D:/cygwin/bin/bash -c '/bin/test/app.sh 04.10 D:\cygwin\bin\ Test_files
Or Can any one please suggest how to run shell script in java using Cygwin.
Rewriting the Problem:-
When i am trying to run following Command in command prompt it gives error
sh app.sh AK-RD 02.20 D:\cygwin\bin\Test_files
Error:-C:\Documents and Settings\sh app.sh AK-RD 02.20 D:\cygwin\bin\Test_files
/usr/bin/app.sh: line 51: lib/lib.sh: No such file or directory
But if i run the same command at
D:cygwin\bin\Test>sh app.sh AK-RD 02.20 D:\cygwin\bin\Test_files
It works fine. Can any one suggest me how to avoid this kind of errors.
Runtime run = Runtime.getRuntime();
Process p = run.exec("D:/cygwin/bin/bash -c \'/bin/test/app.sh 04.10 D:\cygwin\bin\ Test_files");
p.waitFor();

Categories