What am I missing? My research has told me that the following message means the system can not find the specified command.
Cannot run program "dir": CreateProcess error=2, The system cannot find the file specified
But the system finds the command when I type it in a command prompt.
My Java command follows:
Process process = new ProcessBuilder(args).start();
11 28309
May be the path you specified is wrong.
If the exe is in c drive. Then typically, you will write it as
But this need to be written as
With out the code it is hard to guess. Can you post the code?
Regards
Dheeraj Joshi
My code was not working (same error) so I copied an example from the internet (that looked good to me). Here is the example I copied: - package tests;
-
-
import java.io.*;
-
import java.util.*;
-
-
public class DoProcessBuilder {
-
public static void main(String args[]) throws IOException {
-
-
if (args.length <= 0) {
-
System.err.println("Need command to run");
-
System.exit(-1);
-
}
-
-
Process process = new ProcessBuilder(args).start();
-
InputStream is = process.getInputStream();
-
InputStreamReader isr = new InputStreamReader(is);
-
BufferedReader br = new BufferedReader(isr);
-
String line;
-
-
System.out.printf("Output of running %s is:",
-
Arrays.toString(args));
-
-
while ((line = br.readLine()) != null) {
-
System.out.println(line);
-
}
-
-
}
-
}
The arg pasted is "dir".
args is an array. You can not pass whole array.
It must be something like - Process process = new ProcessBuilder(args[0]).start();
Can you traverse through args array and figure out in which index the command is present and use it.
Regards
Dheeraj Joshi
Take a look at the ProcessBuilder class here.
In particular look at the constructors .
Regards
Dheeraj Joshi
Thanks for responding! For clarity I have changed the source as is listed below. No matter what I do I get the same error message: - package tests;
-
-
import java.io.*;
-
import java.util.*;
-
-
public class DoProcessBuilder {
-
public static void main(String args[]) throws IOException {
-
-
Process process = new ProcessBuilder("dir").start();
-
InputStream is = process.getInputStream();
-
InputStreamReader isr = new InputStreamReader(is);
-
BufferedReader br = new BufferedReader(isr);
-
String line;
-
-
System.out.printf("Output of running %s is:",
-
Arrays.toString(args));
-
-
while ((line = br.readLine()) != null) {
-
System.out.println(line);
-
}
-
-
}
-
}
is "dir" a process?
If you try to execute notepad, i am sure it will execute. Quick execute of following code executed notepad. - String args1 = "notepad";
-
Process process = null;;
-
try {
-
process = new ProcessBuilder(args1).start();
-
} catch (IOException e) {
-
e.printStackTrace();
-
}
-
Similarly you must execute the process which you want.
Regards
Dheeraj Joshi
Your right... Funny the example I copies did a "dir"... What I really want to do is invoke a Java program as a seperate process. If there a way to do this?
Yes, you can invoke a separate Java process inside another.
Regards
Dheeraj Joshi
Maybe I should start from the beginning... I have a TCP/IP socket server that needs to send information to a Syslog Deamon (UDP Port 514). When this TCP/IP socket server attempts to open the UDP port it gets a bind failure. I was led to believe that a TCP/IP Socket Server could not open a UDP port because they conflict with each other. My planned solution is to write the information to a temporary file and spin off another java program (running in a different process ID) to send the information in the temp file to the SYSLOG Deamon.
Does anyone have a way to do this?
I have figured out how to issue the Java command...
p = new ProcessBuilder("cmd", CMD).start();
cmd is a process CMD = "Java ... "
Thanks for all your help.
@Donald Likens
what you understand please share with me, i am also trying to do that through java program but i got the error - "start cmd /c": CreateProcess error=2, The system cannot find the file specified
why this error comes what is reason behind it and how to resolve it
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ronald W. Roberts |
last post by:
I'm not sure where this routine came from,
but here is the problem. On certian computers
this error occurs, but it does not on others.
The error is: "Undefined Function "DIR" in expression".
...
|
by: per9000 |
last post by:
Dear Black Knight,
I have no quarrel with you sir Knight, but I must import your parents.
SHORT VERSION:
I tried three variants of "from ../brave.py import sir_robin", one
works. I want...
|
by: laredotornado |
last post by:
Hi,
I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed
using Apache's apxs and the php library was installed to
/usr/local/php. However, when I set my "error_reporting"...
|
by: contractsup |
last post by:
Environment:
$ uname -a
AIX <withheld2 5 000100614C00
$ db2level
DB21085I Instance "<withheld>" uses "32" bits and DB2 code release
"SQL08024"
with level identifier "03050106"....
|
by: ManningFan |
last post by:
Due to the way our IT group has set up our servers, we are not allowed
to use the Shell() command.
We are already doing a similar action with an FTP command. Our code
is thus:
sExe =...
|
by: =?utf-8?B?Qm9yaXMgRHXFoWVr?= |
last post by:
Hello,
(sorry to begin with Java in a Python list ;-)
in Java, when I want to pass input to a function, I pass
"InputStream", which is a base class of any input stream.
In Python, I found...
|
by: perlvasu |
last post by:
6 jobs are running at the same time and accessing same dbm file for writing and reading. These are daily jobs and failing only some times not regularly. So i thought of this is just because of dead...
|
by: chrisbirk |
last post by:
Hi!
I want to write an application on windows xp, which iterates n times a model script (exe) and copies every single run the results (multiple files such as text, maps, subfolders,etc) from the...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |