Hi,
I want to execute unix commands(pdftops and ps2pdf) in windows system using java environment. but m getting error.plz help me.
here is my code:

public static  Process p1;
public static Runtime rt;
 rt = Runtime.getRuntime();
            ////linux commands
            filename=args[0].replace(".pdf","temp.pdf");
            String pdftopsCmd ="pdftops "+args[0]+" temp.ps";
            String pstopdfCmd="ps2pdf temp.ps " +filename;
            p1 = rt.exec(pdftopsCmd);//p1=process
            Thread.sleep(10000);
            p1=rt.exec(pstopdfCmd);

and the error is :

Exception in thread "main" java.io.IOException: CreateProcess: pdftops Test2.pdf temp.ps error=2
	at java.lang.ProcessImpl.create(Native Method)
	at java.lang.ProcessImpl.<init>(Unknown Source)
	at java.lang.ProcessImpl.start(Unknown Source)
	at java.lang.ProcessBuilder.start(Unknown Source)
	at java.lang.Runtime.exec(Unknown Source)
	at java.lang.Runtime.exec(Unknown Source)
	at java.lang.Runtime.exec(Unknown Source)

Recommended Answers

Is that maybe because Unix commands don't execute when you aren't in a Unix environment.. ?

Jump to Post
Answered by jwenting 1,823 in a post from

First learn the difference between DOS, Windows, and Unix.

Jump to Post

All 7 Replies

Is that maybe because Unix commands don't execute when you aren't in a Unix environment.. ?

Hi,
I want to execute unix commands(pdftops and ps2pdf) in windows system using java environment. but m getting error.plz help me.
here is my code:

public static  Process p1;
public static Runtime rt;
 rt = Runtime.getRuntime();
            ////linux commands
            filename=args[0].replace(".pdf","temp.pdf");
            String pdftopsCmd ="pdftops "+args[0]+" temp.ps";
            String pstopdfCmd="ps2pdf temp.ps " +filename;
            p1 = rt.exec(pdftopsCmd);//p1=process
            Thread.sleep(10000);
            p1=rt.exec(pstopdfCmd);

and the error is :

Exception in thread "main" java.io.IOException: CreateProcess: pdftops Test2.pdf temp.ps error=2
	at java.lang.ProcessImpl.create(Native Method)
	at java.lang.ProcessImpl.<init>(Unknown Source)
	at java.lang.ProcessImpl.start(Unknown Source)
	at java.lang.ProcessBuilder.start(Unknown Source)
	at java.lang.Runtime.exec(Unknown Source)
	at java.lang.Runtime.exec(Unknown Source)
	at java.lang.Runtime.exec(Unknown Source)

There are tools available such as Cygwin which gives linux environment in the Windows. First install it and then try to execute commands on it.

Is that maybe because Unix commands don't execute when you aren't in a Unix environment.. ?

I too don't understand this concept but my TL is telling that it's possible. This is like a nightmare to me. Don't know how to resolve.

Hi~ I'am S.Korean .Your coding is very good...but..like ~ below...
...
try {
Thread.sleep(10000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
..

Thank you navin, I tried that link before but of no use (Thanks sridhar for suggesting the tool )As of now i am just compiling the java file in windows m/c and executing in Linux m/c. The code that i have provided very well execute in linux m/c. Any1 of u got any clue (how to run on windows) then please let me know.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.