LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-03-2007, 02:37 AM   #1
manolakis
Member
 
Registered: Nov 2006
Distribution: xubuntu
Posts: 464

Rep: Reputation: 37
java and terminal window commands


Hey there
I am interested in creating a java program which uses a print statement to the terminal window which actually is a command.
To be more clear consider the following example.
Quote:
System.out.println("mkdir aDir");
Somehow like that a new directory should be created.
Is something like that possible?

Thanks for your time
 
Old 02-03-2007, 03:03 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Ubuntu/WSL
Posts: 9,785

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
It is doable by using the Runtime.exec() method, but it is usually not a good idea to run external programs from Java.
Especially when the job can be done in Java, like in this case (you can create a directory in pure Java), which would make your application more portable.
 
Old 02-03-2007, 04:07 PM   #3
manolakis
Member
 
Registered: Nov 2006
Distribution: xubuntu
Posts: 464

Original Poster
Rep: Reputation: 37
Hey again
Many thanks for your reply
I would like once more again your advice. I have a C program which can be executed like:
Quote:
./program < input > output
As you can see it takes some input from a text file and outputs to another file.
What i want to do is to run the C program then start up Java program which reads the output, determines if it is appropriate and if it's not then it starts up again the C program.
All of that should happen until i get the desired output
The fact is that i dont need to make any change to C or Java files. In other words they dont need to be compiled again

Any ideas?
 
Old 02-03-2007, 04:43 PM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Ubuntu/WSL
Posts: 9,785

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
How is the java program reporting the input is not appropriate ?
 
Old 02-03-2007, 11:27 PM   #5
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
You will need to spawn the C application from within the Java program, and make use of the java.util.Scanner class (it's the easiest class in the world for obtaining input).

Pretty much, you'll need to spawn the C app. from within the java.util.Splitter() instance, like so:
Code:
java.util.Scanner s = new java.util.Scanner(Runtime.exec("application"));
...I'm not sure if that code is correct, but it should come very close - I'm at work right now, and don't have access to a Java compiler.

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
making a script that opens terminal and enter commands into that terminal Cinematography Linux - General 8 12-16-2008 11:34 AM
Terminal commands Ermen Linux - Newbie 1 11-23-2004 11:13 AM
2 Questions: java calling system commands? PERL vs Java? randomx Programming 28 11-28-2003 09:24 PM
Terminal commands newtothegame Linux - Newbie 2 09-16-2003 05:52 PM
Not accepting commands in the Terminal Window Rutnut Linux - Newbie 1 12-13-2000 10:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration