The script I'm trying to run is 'root/tufimail'. The code below produces this error
Exception in thread "main" java.io.IOException: Cannot run program "root/tufimail": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at rss.RSSFeedParser.main(RSSFeedParser.java:450)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
Is there something wrong with my syntax? Why is it not finding the file?
Runtime r= Runtime.getRuntime();
Process exec = r.exec("/root/tufimail \"<person#aplace.com; person2#aplace.com>\" \"Tesing 2 recipients\" \"I love booty\"");
try {
exec.waitFor();
System.out.println(exec.getOutputStream());
} catch (InterruptedException ex) {
Logger.getLogger(RSSFeedParser.class.getName()).log(Level.SEVERE,null, ex);
}
Here are the file properties:
Here is the linux directory :/root/tufimail
[root#abox ~]# ls -l tufimail
-rwxr-xr-x 1 root root 595 Aug 20 14:35 tufimail
Related
Getting issue Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified while executing java program from intellij but when executing same command from cmd prompt then it's working properly.
public class TestRunProgram {
public static void main(String[] args) throws IOException {
String commandRun = "aws apigateway get-api-keys --profile awsProdUser --region eu-west-1";
System.out.println(commandRun);
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(commandRun);
}}
Getting below issue after execution
java.io.IOException: Cannot run program "aws": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
I have found a solution after installing AWS CLI for windows. Initially, I was installing it from python.
https://docs.aws.amazon.com/cli/latest/userguide/install-windows.html
These errors have been generated when running a chatbot java program on windows platform in the Netbeans IDE.
Maybe I am missing the build path for some process.
java.io.IOException: Cannot run program "clear": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at chatbot.chatbot.main(chatbot.java:29)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
at java.lang.ProcessImpl.start(ProcessImpl.java:137)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 4 more
BUILD SUCCESSFUL (total time: 4 seconds)
Can anyone please provide me a solution to this problem..
I can't install Java on the computer, I only have a 'Java folder' on my desktop. Because of that executing 'cmd.exe' commands with Java doesn't work. Is there any method of pointing to the 'cmd.exe' and telling java to run a command using it?
I mean somethind similar to what I do in my 'start.bat' file i use to run .jar's - start C:\Users\kamilkime\Desktop\JEclipse\Java\jdk1.7.0_75\bin\java -jar Calculator.jar
I tried using this two methods, both don't work and throw the same exception:
//Method 1
Runtime.getRuntime().exec("cls");
//Method 2
ProcessBuilder builder = new ProcessBuilder("cls");
builder.start();
//Exception stacktrace
java.io.IOException: Cannot run program "cls": CreateProcess error=2, Nie można odnaleźć określonego pl
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at com.gmail.kamilkime.Main.clearConsole(Main.java:82)
at com.gmail.kamilkime.Main.start(Main.java:61)
at com.gmail.kamilkime.Main.main(Main.java:36)
Caused by: java.io.IOException: CreateProcess error=2, Nie można odnaleźć określonego pl
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:385)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
... 6 more
//edit 08.10.2015
Ok, so thanks to #9dan I've managed to run a console window, but... Now I can't do anything with it - cannot println() a message, cannot get a user input. Is it posibble to do sth like that (printing/getting input)?
BTW, the thing I'm trying to do the whole time is finding a way to enable the console program by double-clicking the .jar file, not by using 'java' command in 'cmd.exe'.
Now, I'm using this code and I'm stuck - I don't know what to do: http://pastebin.com/VLkr1RFd
What is the difference between this-
Process process=Runtime.getRuntime().exec(
new String[] {"cmd", "/c", command.toString()},
null, new File("D:/test"));
and this-
Process process=Runtime.getRuntime().exec(
command.toString(), null, new File("D:/test"));
If I use the first one it's working but if I use the second one it's giving below exception-
java.io.IOException: Cannot run program "gst" (in directory "D:\test"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:450)
at CommandInvoker.main(CommandInvoker.java:38)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:385)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 3 more
I am trying to run some Mercurial commands from a java program. I build my Process using a ProcessBuilder like this:
final ProcessBuilder procBuilder = new ProcessBuilder("hg", "log");
procBuilder.directory(new File("/Users/feuerball/workspace/www"));
final Process proc = procBuilder.start();
The folder www contains a Mercurial repository, hg is installed and in the systems PATH. But my program throws an exception when I start the process. This is the stacktrace:
Exception in thread "main" java.io.IOException: Cannot run program "hg" (in directory "/Users/feuerball/workspace/www"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1042)
at de.feuerball.tests.Test.main(Test.java:16)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:185)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1023)
... 1 more
Why do I get this error?
Update
To show that the directory does exist, I have changed the code a little bit:
final File repo = new File("/Users/feuerball/workspace/www");
System.out.println("Directory? " + repo.isDirectory());
System.out.println("Readable? " + repo.canRead());
System.out.println("Writable? " + repo.canWrite());
final ProcessBuilder procBuilder = new ProcessBuilder("hg", "log");
procBuilder.directory(repo);
final Process proc = procBuilder.start();
Now here is the proof:
Directory? true
Readable? true
Writable? true
Exception in thread "main" java.io.IOException: Cannot run program "hg" (in directory "/Users/feuerball/workspace/www"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1042)
at de.brushmate.tests.Test.main(Test.java:22)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:185)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1023)
... 1 more
ProcessBuilder doesn't use the env variable PATH, it can't find "hg", you need to specify the absolute path to "hg" (like /usr/bin/hg if you're using Linux)