• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Runtime.getRuntime().exec()

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,
I am using a Linux commond in the Runtime.getRuntime().exec(String) funtion which
works in the following way:
1. smbclient -M testing "enter"
(smbclient is the command, -M is the option, testing is the host/Machine to whom i want to send the mess, "enter" means hit the Enter key on keyboard).
2. Then type my message and press ctrl+d to send the message.
Because i am sending message programmatically from java. i do it the following way:
char cCtrl_d = 40;
Runtime.getRuntime().exec("smbclient -M \n My Message "+cCtrl_d);
This does not works as the actuall working of command smbclient is two part, viz;
1. smbclient -M testing "Enter"
2. My Message + ctrl+d
how do i give two-part command in sequences, to the Process?
/*
i belive Runtime.getRuntime().exec(String)creates a seperate process.
*/
looking forward to some very urgent help
ajay
 
author
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"achaturvedi",
Thanks for participating here at the Ranch. However, the name you are using does not comply with our naming convention described at http://www.javaranch.com/name.jsp . Please log in with a new name, which meets these requirements.
You can change your name here.
Thanks.
Sean
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"MyMessage" is not part of the command, but is read by smbclient from stdin.
So exec the smbclient command, get the OutputStream from the process, which will connect you with smbclient's stdin, and write your message to that stream.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try writing ur commands in a file basically executable file and give the path of that file as parameter to the Runtime.exec(String str) method.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Get the OutputStream from the process(which is the stdin input of the process), using the method process.getOutputStream().
And write whatever message you need. When you call the close() method, it will be equivalent to your cntrl D
Do go through this URL javaworld which discuss about the runtime.exec() pitfalls, and ways to avoid some of the exceptions.
--Vikas
 
ajay chaturvedi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all,
above both approach work for me,
Thank you again.
ajay
 
reply
    Bookmark Topic Watch Topic
  • New Topic