aspose file tools*
The moose likes Applets and the fly likes java.io.IOException: Cannot run program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "java.io.IOException: Cannot run program "cmd.exe": CreateProcess error=5, Access is denied" Watch "java.io.IOException: Cannot run program "cmd.exe": CreateProcess error=5, Access is denied" New topic
Author

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

Alka Gupta
Greenhorn

Joined: Oct 02, 2012
Posts: 4
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

Joined: May 03, 2008
Posts: 4522
    
    5

Alka, welcome to the Ranch! Please BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/advanced-java/63494-java-io-ioexception-cannot-run-program-cmd-exe-createprocess-error-5-access-denied.html
https://forums.oracle.com/forums/thread.jspa?threadID=2446927

db


luck, db
There are no new questions, but there may be new answers.
Alka Gupta
Greenhorn

Joined: Oct 02, 2012
Posts: 4
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
Ranch Hand

Joined: Aug 27, 2012
Posts: 953
    
  10

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

Joined: Oct 02, 2012
Posts: 4
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

Joined: May 03, 2008
Posts: 4522
    
    5

Wasn't this adequately answered hours earlier in one of the cross posts?
Alka Gupta
Greenhorn

Joined: Oct 02, 2012
Posts: 4
That didnt solve my problem, I am still having the issue
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 953
    
  10

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.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.io.IOException: Cannot run program "cmd.exe": CreateProcess error=5, Access is denied
 
Similar Threads
how to synchronize the databases(different locations)
Unix With Java....
Using DOS commands in Java
Runtime.getRuntime().exec() fails intermittently.
java.io.IOException:CreateProcess error=5, Access is denied(While running build.xml in Ant editor)