• 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() 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
 
Sheriff
Posts: 22783
131
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
Sheriff
Posts: 22783
131
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
 
Everybody's invited. Except this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic