Solved

problem in running Runtime.exec command....

Posted on 2004-04-28
6
1,880 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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 64
Android studio getdrawable(int) is deprecated 4 123
jmss example java 2 24
Java program running SQL query 5 38
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

820 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