Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.io.IOException: Cannot run program "cmd.exe": CreateProcess error=5, Access is denied

 
Alka Gupta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a part of diagnostic effort we copied cmd.exe from system32 folder of windows to C:\\ drive and tried to run from an applet and get following exception :

java.io.IOException: Cannot run program "cmd.exe": CreateProcess error=5, Access is denied

The problem is with JRE 1.7 whereas on JRE 1.6 it runs fine.

Renamed it to cmdx , runs fine.

So any program named as cmd does not run at all.

The applet jar is signed.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
 
Alka Gupta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More information

Runtime.getRuntime().exec(new String[] { "C:\\cmd.exe"});

as well as

Process p = new ProcessBuilder("C:\\cmd").start();

None of them work, It used to work before with jre 1.6 and now we started certifying 1.7 for our software we this issue.

I have read many forums and have asked on Java forum, windows forum and oracle forum but I havent got any answer yet
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I must be missing something . Why do you need to name the executable you are trying to exec() cmd.exe ? Why can't you call it something like fred.exe ?
 
Alka Gupta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Runtime.getRuntime().exec(new String[] { "cmd.exe", "/c", udoc.getFilename() });

This is the original code I'm trying to execute and fails on cmd.exe so I broke it to see how can I fix the cmd problem
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wasn't this adequately answered hours earlier in one of the cross posts?
 
Alka Gupta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That didnt solve my problem, I am still having the issue
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alka Gupta wrote:Runtime.getRuntime().exec(new String[] { "cmd.exe", "/c", udoc.getFilename() });

This is the original code I'm trying to execute and fails on cmd.exe so I broke it to see how can I fix the cmd problem


So can we start again. The copying of cmd.exe is a red-herring and all you are trying to do is execute a 'bat' file using Runtime.exec() but it fails. Have you read all the parts of http://www.javaworld.com/jw-12-2000/jw-1229-traps.html and implemented ALL the recommendations? If not then do so and post the code, all the error messages, the process 'stdout' content, the process 'stderr' content and the process exit code.

Note - I use Runtime.exec() to execute 'BAT' files without problems on Windows Xp and Windows 7. The single most important thing to do is to fully read the 'stdout' and 'stderr' streams in separate threads and for diagnostic purposes one needs to print the content.

You seem to be doing this within an Applet so you must of course sign the Applet. To make it easy to test the code you should isolate the whole into it's own class; you can then do the basic tests without having to continually deploy the applet and clear the Applet cache. Once you have the basics working you can then use this class in the Applet.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic