This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception error:Cannot run program "C:\Users\x\Desktop": CreateProcess error=5, Access is denied.

 
syed vaseem
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.PrintStream;
import java.util.*;
public class NewThread implements Runnable{
Thread t;

NewThread(){
t = new Thread(this, "Demo Thread");
System.out.println("child thread:" + t);
t.start();
}


long startTime = System.currentTimeMillis();
public void run(){
Runtime r = Runtime.getRuntime();
Process p = null;
String s = "C:\\Users\\x\\Desktop\\ java -jar helol.jar";

try
{
p = r.exec(s);
p.waitFor();

}
catch (Exception e)
{
System.out.println("Exception error:" + e.getMessage());
}
System.out.println("Project1 returned:" + p.exitValue());
System.out.println("child thread exiting ");
long endTime = System.currentTimeMillis();
System.out.println("Total elapsed time in execution of given .exe file in milliseconds is :" + (endTime-startTime));
System.out.println("Heap utilization Statistics in Bytes");
System.out.println("Used Memory:"+ (r.totalMemory() - r.freeMemory()));
System.out.println("Free Memory:"+ r.freeMemory());
System.out.println("Total Available Memory:" + r.totalMemory());
System.out.println("Maximum Available Memory:" + r.maxMemory());

}
}

class ThreadDemo {
public static void main(String args[]){
new NewThread();
try {
for(int i=05;i>0;i--){
System.out.println("Main Thread:" + i);
Thread.sleep(1000);
}
} catch (InterruptedException e){
System.out.println("Main thread Interrupted");
}
System.out.println("Main thread exiting");
}

}


please help me out ASAP... i am trying to execute a jar file through this program in eclipse but it's showing an error - createprocess=5 access is denied and i tried to change the permissions of respective folders and directory but couldn't work and i made changes in configuration file of eclipse i.e eclipse.ini but still i am facing prob.
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
split your command into



and use http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Runtime.html#exec(java.lang.String[])
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String s = "C:\\Users\\x\\Desktop\\ java -jar helol.jar";

There is a space before java, I think may be that is the error.
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that your "java" executable is located in C:\Users\x\Desktop? Because that's what you're trying to do here (apart from the space).
I think you want to execute "java -jar helol.jar" from directory C:\Users\x\Desktop. There's an overloaded exec method for that:
And when you're working with Runtime.exec or ProcessBuilder, make sure to have read When Runtime.exec() won't.
 
syed vaseem
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for everyone.... 3rd post by ROB SPOOR is working....i am really so happy that i got solved my prob... thanks to everyone............... love this forum
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Vijitha Kumara
Bartender
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Syed Vazzz,

Next time please UseCodeTags when posting code in the forums. Unformatted code makes it hard to read.
 
syed vaseem
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah sure sir
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic