Solved

problem in running Runtime.exec command....

Posted on 2004-04-28
6
1,863 Views
Last Modified: 2012-06-21
Hi,
I need to run a ghostscript command using java. For that I am using Runtime.exec command. when I compile the class get this error :-
java:22: non-static method exec(java.lang.String) cannot be referenced from a static context
Here is my code:-

import java.lang.*;
public class TestGS
{
   public static void main (String[] args)
  {
    String str;
    String str1;
    char c;
    String file1;
    String file2;
    String mainfile;
    file1="C:\\1.pdf";
    file2="C:\\2.pdf";
    mainfile="C:\\3.pdf";
    c= (char) 34;
    str1 = c + mainfile + c + " " + c + file1 + c + " " + c + file2 + c;
    System.out.println ("str = " + str1);
    str = "C:\\gs\\gs8.11\\bin\\gswin32c.exe -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -  sOutputFile=" + str1;
    System.out.println ("str = " + str);
    Runtime.exec(str);
  }
}

Please help.
Kirti
0
Comment
Question by:kirtirani
  • 2
  • 2
  • 2
6 Comments
 
LVL 92

Assisted Solution

by:objects
objects earned 75 total points
ID: 10945567
Runtime.getRuntime().exec(str);
0
 
LVL 9

Accepted Solution

by:
mmuruganandam earned 50 total points
ID: 10945626
better choice would be string array to the exec as parameter

String command[] ={"C:\\gs\\gs8.11\\bin\\gswin32c.exe", "-q", "-dNOPAUSE", "-dBATCH", "-sDEVICE=pdfwrite", "-sOutputFile=" + str1};

Runtime.getRuntime().exec(command);
0
 

Author Comment

by:kirtirani
ID: 10945776
thanks.... it works :-)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:kirtirani
ID: 10945820
As both of your salutions are same,I split the points to both of you.
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10949231
thanx :-)
0
 
LVL 92

Expert Comment

by:objects
ID: 10954586
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Application launch issue with Apache Tomcat 5 24
backtracking recursion  code 19 54
Java / Linux and Regular Expressions 11 71
table example 4 25
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now