• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Running commands using Runtime.getRuntime().exec() in Unix  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How do i run commands which contain piping(|). I believe that being a shell feature it wont be recognized by java.

What i am trying to do is something like :

the output i get returns all the processes and doesn't seem to go beyond the piping.

Is there any solution to this?
 
Ranch Hand
Posts: 1141
1
Java Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arjun,
Method exec is not a UNIX shell interpreter.
If you want to use it for something more complex than a single, simple UNIX command, I suggest creating a shell script and launching the shell script from the exec method.
If you haven't already done so, I suggest you read the following article from JavaWorld:

When Runtime.exec() won't

Good Luck,
Avi.
 
Arjun Murthy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thansk for your reply Avi.
In the command i want to run "ps -ef | grep /home/abcd" the "home/abcd" part is not known beforehand. I am getting that as an input and creating the command runtime so i dont think making a shell script would be possible. Is there any other way?

Thanks
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arjun,
You wrote:


In the command i want to run "ps -ef | grep /home/abcd" the "home/abcd" part is not known beforehand. I am getting that as an input and creating the command runtime so i dont think making a shell script would be possible.


Of-course it would be possible, since shell scripts accept command-line arguments.
Perhaps you need to brush up on your UNIX?
Allow me to suggest the Unix CD Bookshelf.

Good Luck,
Avi.
 
Arjun Murthy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a beginner to unix so i apologize for the ignorance. However the input is coming from a form in a web application and not command line. Would that make any difference?
 
Arjun Murthy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help Avi.

Upon further googling I found the following solution



 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!