The Artima Developer Community
Sponsored Link

Java Answers Forum
a complicated question

3 replies on 1 page. Most recent reply: Jun 23, 2002 11:09 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
simon

Posts: 2
Nickname: amator
Registered: Jun, 2002

a complicated question Posted: Jun 19, 2002 4:53 AM
Reply to this message Reply
Advertisement
My question is occured during the program call the cmd.exe in windows or gnome-terminal in linux.I want the program to invoke a terminal and then execute the command on the terminal later defined by the program.The process is like that a you compile and executive a exe file . Visual c++ will executive your exe file in a terminal and in the terminal you can input the required value and get the result.The executive process is like that you run the exe file straightly in the terminal,it can provide a prompt to input the new value and it can output the result too. In my option ,I want to obstain the goal. I had tried it with Runtime.exec() but failed at last.
So i'm very puzzled about how to obstain the aim.


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: a complicated question Posted: Jun 19, 2002 10:57 AM
Reply to this message Reply
This isn't really a Java question, but I'll let you off the hook this time. However, as punishment, I'll only give you the answer for the Windows platform. When you launch the command shell with exec(), you need to pass the program that you want to run (which could be a shell script you dynamically generated, by the way). To do this, you can use the /c option if you want the shell to terminate when the process is complete, or the /k option if you want it to remain. So, if it was a Java program you wanted to launch in another shell, you call "cmd /c java [YourProgramName]" -- By the way, I would usually recommend not using the name "cmd" directly, but instead suggest getting it from the %comspec% environment variable; however I don't know how to get ahold of this variable in Java, as it doesn't seem to be one of the environment variables that is passed through and exposed via the system properties.

simon

Posts: 2
Nickname: amator
Registered: Jun, 2002

Re: a complicated question Posted: Jun 23, 2002 6:50 PM
Reply to this message Reply
> This isn't really a Java question, but I'll let you
> off the hook this time. However, as punishment,
> I'll only give you the answer for the Windows
> platform. When you launch the command shell with
> exec(), you need to pass the program that you want to
> run (which could be a shell script you dynamically
> generated, by the way). To do this, you can use the
> /c option if you want the shell to terminate when the
> process is complete, or the /k option if you want it
> to remain. So, if it was a Java program you wanted
> to launch in another shell, you call "cmd /c java
> [YourProgramName]" -- By the way, I would usually
> recommend not using the name "cmd" directly, but
> instead suggest getting it from the %comspec%
> environment variable; however I don't know how to get
> ahold of this variable in Java, as it doesn't seem to
> be one of the environment variables that is passed
> through and exposed via the system properties.

Thank you for your answer,but the answer is not suit for my question.I think if you use the exec(),you can derive output and error information from it. But how can i input the data if the program need it?

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: a complicated question Posted: Jun 23, 2002 11:09 PM
Reply to this message Reply
Ah I guess your question was a bit too complicated; I didn't quite apprehend the full meaning. I haven't tried this, but I think what you'll need to do is use the getInputStream() and getOutputStream() methods of the process object returned from exec().

Flat View: This topic has 3 replies on 1 page
Topic: draw Previous Topic   Next Topic Topic: New to programming

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use