Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

problem in running Runtime.exec command....

Posted on 2004-04-28
6
Medium Priority
?
1,932 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 92

Assisted Solution

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

Accepted Solution

by:
mmuruganandam earned 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

604 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