473,322 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

java processbuild CreateProcess error=2 for command "Dir"

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();
Apr 7 '11 #1
11 28310
Dheeraj Joshi
1,123 Expert 1GB
May be the path you specified is wrong.

If the exe is in c drive. Then typically, you will write it as
Expand|Select|Wrap|Line Numbers
  1. c:\temp.exe
But this need to be written as
Expand|Select|Wrap|Line Numbers
  1. c:\\temp.exe
With out the code it is hard to guess. Can you post the code?

Regards
Dheeraj Joshi
Apr 7 '11 #2
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:

Expand|Select|Wrap|Line Numbers
  1. package tests;
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5.  
  6. public class DoProcessBuilder {
  7.   public static void main(String args[]) throws IOException {
  8.  
  9.     if (args.length <= 0) {
  10.       System.err.println("Need command to run");
  11.       System.exit(-1);
  12.     }
  13.  
  14.     Process process = new ProcessBuilder(args).start();
  15.     InputStream is = process.getInputStream();
  16.     InputStreamReader isr = new InputStreamReader(is);
  17.     BufferedReader br = new BufferedReader(isr);
  18.     String line;
  19.  
  20.     System.out.printf("Output of running %s is:", 
  21.        Arrays.toString(args));
  22.  
  23.     while ((line = br.readLine()) != null) {
  24.       System.out.println(line);
  25.     }
  26.  
  27.   }
  28.  }  
The arg pasted is "dir".
Apr 7 '11 #3
Dheeraj Joshi
1,123 Expert 1GB
args is an array. You can not pass whole array.
It must be something like
Expand|Select|Wrap|Line Numbers
  1. 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
Apr 7 '11 #4
Dheeraj Joshi
1,123 Expert 1GB
Take a look at the ProcessBuilder class here.

In particular look at the constructors .

Regards
Dheeraj Joshi
Apr 7 '11 #5
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:

Expand|Select|Wrap|Line Numbers
  1. package tests;
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5.  
  6. public class DoProcessBuilder {
  7.   public static void main(String args[]) throws IOException {
  8.  
  9.     Process process = new ProcessBuilder("dir").start();
  10.     InputStream is = process.getInputStream();
  11.     InputStreamReader isr = new InputStreamReader(is);
  12.     BufferedReader br = new BufferedReader(isr);
  13.     String line;
  14.  
  15.     System.out.printf("Output of running %s is:", 
  16.        Arrays.toString(args));
  17.  
  18.     while ((line = br.readLine()) != null) {
  19.       System.out.println(line);
  20.     }
  21.  
  22.   }
  23.  }
Apr 7 '11 #6
Dheeraj Joshi
1,123 Expert 1GB
is "dir" a process?
If you try to execute notepad, i am sure it will execute. Quick execute of following code executed notepad.

Expand|Select|Wrap|Line Numbers
  1. String args1 = "notepad";
  2. Process process = null;;
  3. try {
  4.     process = new ProcessBuilder(args1).start();
  5. } catch (IOException e) {
  6.     e.printStackTrace();
  7. }
  8.  
Similarly you must execute the process which you want.

Regards
Dheeraj Joshi
Apr 7 '11 #7
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?
Apr 7 '11 #8
Dheeraj Joshi
1,123 Expert 1GB
Yes, you can invoke a separate Java process inside another.

Regards
Dheeraj Joshi
Apr 7 '11 #9
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?
Apr 7 '11 #10
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.
Apr 8 '11 #11
@Donald Likens

what you understand please share with me, i am also trying to do that through java program but i got the error
Expand|Select|Wrap|Line Numbers
  1. "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
Jul 10 '12 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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". ...
7
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...
1
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"...
2
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"....
3
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 =...
4
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...
1
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...
6
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...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
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...
1
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)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.