Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

Problems with exec()

Thread view: 
phuonganh.Ng@gmail.com - 26 Oct 2006 23:06 GMT
Hi,
I'm writing a Java GUI for the text parsing program called "Apple Pie
Parser", the program was written in Unix C and have an executable file
(console) for windows. My program's being written in Windows, so I
tried to called the Runtime exec() method to get that .exe file to run
and pass my input into it. But it seems like i couldn't call it, cuz
nothing came up, and even when i tested, tried to call "cmd.exe",
nothing happened either. I'm wondering if there's anything to solve
this.

Thanks.
IchBin - 27 Oct 2006 00:30 GMT
> Hi,
> I'm writing a Java GUI for the text parsing program called "Apple Pie
[quoted text clipped - 7 lines]
>
> Thanks.

Not to put you off but maybe this article will help you out:

When Runtime.exec() won't
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

Signature

Thanks in Advance...                  http://ichbin.9999mb.com
IchBin, Pocono Lake, Pa, USA          http://weconsultants.phpnet.us
______________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)

Andrew Thompson - 27 Oct 2006 06:01 GMT
> > Hi,
> > I'm writing a Java GUI for the text parsing program called "Apple Pie
> > Parser", the program was written in Unix C and have an executable file
> > (console) for windows. My program's being written in Windows, so I
> > tried to called the Runtime exec() method to get that .exe file to run
> > and pass my input into it. But it seems like i couldn't call it,

*  Call it what?

> > ...cuz
> > nothing came up, and even when i tested, tried to call "cmd.exe",
> > nothing happened either. I'm wondering if there's anything to solve
> > this.
...
> Not to put you off but maybe this article will help you out:

That article is very encouraging.  I only glanced at each of
the five pages, but it indicated* that these type of problems
are easily debugged.

* It dumped stacktraces for every important action where
something could go wrong.
To the OP, have a look at how those code examples
give very *specific* details of what went wrong, down
to the line number.  If looking at that article fails to
sort your immediate problem, I suggest you post a code
example that is self contained, and the first few lines
of the stacktraces it is causing when run.

Andrew T.
Chris Uppal - 27 Oct 2006 10:07 GMT
> I'm writing a Java GUI for the text parsing program called "Apple Pie
> Parser", the program was written in Unix C and have an executable file
[quoted text clipped - 4 lines]
> nothing happened either. I'm wondering if there's anything to solve
> this.

That program appears to read from its stdin and write to its stdout.  If your
Java program is intended to make use of that (making use of the input and
output streams in the java.lang.Process instance corresponding to your exec()ed
program), then the most likely problem is that you have written to
the program's stdin but not flushed your output stream.

   -- chris
phuonganh.Ng@gmail.com - 27 Oct 2006 20:45 GMT
Thanks for all your help, i'm still working on the problem. Below is my
code to simply open the application, input a sentence and wanting to
get the output.
----------------------------------------
try {
      String out;
      Process p =
Runtime.getRuntime().exec("C:/work/APP5.9/bin/app.exe");

      BufferedReader output =  new BufferedReader(new
InputStreamReader(p.getInputStream()));
      BufferedWriter input = new BufferedWriter(new
OutputStreamWriter(p.getOutputStream()));

      input.write("I tripped over a rock as I ran.\n");
      input.flush();

      while ((out = output.readLine()) != null) {
             System.out.println(out);

      }
      output.close();
      p.destroy();
      }
catch (Exception err) {
   err.printStackTrace();
      }
---------------------------------------

It didn't print out anything nor give me any error.
Robert Klemme - 27 Oct 2006 23:03 GMT
> Thanks for all your help, i'm still working on the problem. Below is my
> code to simply open the application, input a sentence and wanting to
[quoted text clipped - 26 lines]
>
> It didn't print out anything nor give me any error.

Depending on what the app does you might have to close the input before
you see anything.

    robert
phuonganh.Ng@gmail.com - 27 Oct 2006 22:36 GMT
Thanks for all your help, i'm still working on the problem. Below is my
code to simply open the application, input a sentence and wanting to
get the output.
----------------------------------------
try {
    String out;
    Process p = Runtime.getRuntime().exec("C:/work/APP5.9/bin/app.exe");

    BufferedReader output =  new BufferedReader(new
InputStreamReader(p.getInputStream()));
    BufferedWriter input = new BufferedWriter(new
OutputStreamWriter(p.getOutputStream()));

    input.write("I tripped over a rock as I ran.\n");
    input.flush();

    while ((out = output.readLine()) != null) {
          System.out.println(out);

    }
    output.close();
    p.destroy();
    }
catch (Exception err) {
    err.printStackTrace();
    }
---------------------------------------

It didn't print out anything nor give me any error.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.