Solved

problem in running Runtime.exec command....

Posted on 2004-04-28
6
1,845 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
Comment Utility
Runtime.getRuntime().exec(str);
0
 
LVL 9

Accepted Solution

by:
mmuruganandam earned 50 total points
Comment Utility
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
Comment Utility
thanks.... it works :-)
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

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

Expert Comment

by:mmuruganandam
Comment Utility
thanx :-)
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
hash value 2 38
Updating Java 9 85
ArrayLists in ArrayLists/HashMaps? 4 38
Understanding websocket example in spring 1 40
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

762 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

7 Experts available now in Live!

Get 1:1 Help Now