How do i execute a shell script in eclipseIDE? - java

i want to execute a sheel on my Eclipse, and am unable to do so, is it because eclipse does not support shell script or do we any plugin for it.
I am executing it like this, and Name is Argument than i am passing to my script as search pattern.
$ String[] commands = {"C:/Users/shreyas.a.ramesh.DIR/workspace/Shellweb/src/Search_file.sh", Name};
And error I get is as follows
java.io.IOException: Cannot run program
"C:/Users/shreyas.a.ramesh.DIR/workspace/Shellweb/src/Search_file.sh": CreateProcess error=2, The system cannot find the file specified
Sorry about the code indentation.

This isn't a Java or Eclipse problem. Shell scripts aren't executable binaries. You'll have to run the shell binary itself with whatever arguments it needs to interpret your script.

Related

Mulesoft cannot run a shell script

I am trying to run a shell script in a flow in Mulesoft's Anypoint Studio.
While I can get some basic shell to run I cannot get my script to run. This is what my script looks like:
#!/bin/ksh
export JWHome=${pwd}
export LOG4J_JAR=$JWHome/lib/log4j-1.2.7.jar
export CLASSPATH=$JWHome/lib/java.jar:$LOG4J_JAR:$JWHome
I set the above script as a payload and execute it from a Groovy script by running:
payload.execute().text
When I run this script I get the following error:
java.io.IOException: Cannot run program "#!/bin/ksh": error=2, No such file or directory
I get the same error when I remove "#!/bin/ksh" - For example when I run Export to set a variable.
How can I get this to run?
I'm assuming that what you did -you didn't provide enough details- is to use a Groovy script to execute the content of a string in the payload using the execute() method. That is failing because a shell script is not a single command. Only a shell can interpret it, but not as command line.
You can try writing the shell script content to a file (example: myscript.sh, or use a temporary name), then execute the shell script by name ("myscript.sh".execute()). You will probably need to add the path to the file is correct otherwise the execute() method may not find it.

ProcessBuilder unable to find Kotlin in path

When I run:
new ProcessBuilder("kotlinc", "-help").start();
I get the error: Cannot run program "kotlinc": CreateProcess error=2, The system cannot find the file specified
I've tried:
If I check my path from windows, it contains C:\Apps\kotlinc\bin, and when I open explorer at that location, there's a file named kotlinc.
If I open cmd.exe anywhere, and run kotlinc, it works just fine.
If I print out my environment:
System.out.print(new ProcessBuilder("kotlinc", "-help").environment().get("Path"));
it contains C:\Apps\kotlinc\bin
If I run new ProcessBuilder("python3", "file.py").start(), it works just fine.
Rebooting my machine
Changing kotlinc to use the full file path is not an acceptable solution, as this is being run across multiple computers and platforms.
As far as I can tell, everything is setup correctly.
Why can't I run kotlinc from ProcessBuilder?
kotlinc is actually a batch file (kotlinc.bat), not a binary file. Therefore, you need to start it by executing the command cmd /c kotlinc.

Execute a shell script (shell script which uses perl and other shell scripts) in Linux from java

I am trying to execute a shell script (that makes use of a perl script and other shell scripts) from java program, however I am not successful, here is what I tried:
On the Linux server, in a folder test1/testJava the following scripts are available:
decode24.sh (the main script I call from java program, this script makes use of the other scripts listed below)
fram.sh
shadow.pl
light.sh
Here is what I try from java:
try {
ConnBean cb = new ConnBean("xx.yyy.zz.p", "user","passme");
ssh = SSHExec.getInstance(cb);
CustomTask ct1 = new ExecShellScript("/test1/testJava", "./decode24.sh", "arg1");
ssh.connect();
net.neoremind.sshxcute.core.Result res = ssh.exec(ct1);
}catch......
Result after execution:
error message:
./decode.sh[17]: shadow.pl: not found [No such file or directory]
./decode.sh[21]: fram.sh: not found [No such file or directory]
The error comes from your decode.sh script. It cannot find the shadow.pl and fram.sh scripts that it executes. Probably because the CWD or path is not set to the script dir when you run the script.
The most robust way to solve it is to change your decode.sh script to use absolute paths to the shadow.pl and fram.sh scripts. That way you can execute decode.sh from any directory.
If you use bash, check out this question for a neat way to resolve the absolute directory to the scripts to avoid hard coding the path.
Let decode.sh find out the directory it is in (see bash solution) and use the path for calling the others.

How to execute my own commands on terminal from java File

I am trying to make a eclipse project in Java to launch commands with some buttons. The libraries of Ros fuerte (These ones i want to use) are correctly installed and concretly i am trying to launch a ros command from a Java File using:
String cmd = "roscore";
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(cmd);
If i launch this command from a current terminal it works, but if i do it from the java file i have a problem because the terminal doesnt recognize the command.
java.io.IOException: Cannot run program "roscore": java.io.IOException: error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:475)
at java.lang.Runtime.exec(Runtime.java:610)
at java.lang.Runtime.exec(Runtime.java:448)
at java.lang.Runtime.exec(Runtime.java:345)
at LaunchTerminal.main(LaunchTerminal.java:24)
I think that i need to add some path or similar but i dont find the information. Does anybody know how to do it?
Thank u.
only normal commands are possible to execute like rm or cd ... al others must be referenced with full path of context
Do the following if you are using the groovy distribution:
String cmd = "source /opt/ros/groovy/setup.bash && roscore";

Executing cmd.exe commands from Java

I'm trying to read a file from the user, in which each line is a cmd.exe command, and run it (it's okay to assume the commands are legal), but when I give a command like echo hi, I get runtime exception error:
Exception in thread "main" java.io.IOException: Cannot run program "echo": CreateProcess error=2, The system cannot find the file specified
I'm trying to run the commands like this:
Runtime.getRuntime().exec(command);
where command = "echo hi". This does work for commands like regedit though, so it seems the runtime I'm getting is like the "run" window and not cmd. Is there a way to run these commands?
That's because echo is not an external executable command (i.e., there is no echo.exe file on your hard disk, unless you put it there yourself). It's an internal command of the shell.
You'll probably find that you need to execute something like:
cmd.exe /c echo hello

Categories

Resources