Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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

 
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.
 
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
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • 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: 5167
11
Netbeans IDE Opera Java
  • 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
Netbeans IDE Java Linux
  • 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.


 
This one time, at bandcamp, I had relations with a tiny ad.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic