• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Runtime.getRuntime().exec() doubt

 
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

From a java program,I want to send a mail...using the sendmail program of the linux machine

This is the command

/usr/sbin/sendmail kumar@Kumar.com <Mail.txt


And the code snippet is



The command is getting executed without any exceptions...but the Mail.txt contents are not coming through in the mail..

What have i missed??

Regards
 
Marshal
Posts: 22446
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't use piping (|) or input/output/error redirection in the exec methods.

Instead, you need to do this yourself. In this case, just copy all input from the file to the process:
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks but is





Process p = Runtime.getRuntime().exec("/usr/sbin/sendmail kumar@Kumar.com");

OutputStream code...sufficient to send out the mail message...

(ignoring the address part)

and when the stream is closed ..message is eent out........

Anything else ...??
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do we need to call

p.destroy

once the execution is complete/exception occurs???

or nullify the process handlers...??
 
Rob Spoor
Marshal
Posts: 22446
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
destroy() should be called to kill the process while it is still running. Calling it when the process has already ended, either successfully or not, does not make any sense anymore since there is no more process to kill.

When the process ends, all is cleaned up automatically. Nullifying never hurts, but it's not necessary.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob for clearing the doubt..and i am able to send the mail by handling the

But whats the way if one wants to send an attachment to the mail...


Regards
 
I guess I've been abducted by space aliens. So unprofessional. They tried to probe me with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic