Uttam Malakar
Uttam Malakar

Reputation: 714

Handle ctrl +d programmatically?

I am trying to execute the following perl script.

  ##some code
  $command = "nail -s this is a test  $email";
  system($command);
  ##some code 

when I run this script, it hangs until I press CtrlD. after pressing CtrlD I get the desired result. My question is how can I hardcode CtrlD in my script?

Upvotes: 3

Views: 690

Answers (3)

Vamsi Boppana
Vamsi Boppana

Reputation: 1

The usual solution is to redirect it to read from /dev/null

Try to use this :

mail -s "Hello Test" -a Attachment email-address  </dev/null

or, if you have any email body

mail -s "Hello Test" -a Attachment email-address  <emailbodyfile.txt

Upvotes: 0

marderh
marderh

Reputation: 1256

I suppose you call mailx. nail ist most likely an alias. It expects input from STDIN, which is ended with CtrlD. You could workaround like this to send an empty mail:

$command = 'echo "" | nail -s SUBJECT ' . $email;

Upvotes: 1

Sibster
Sibster

Reputation: 3189

The mail program expects an . on a line alone to show it is the end of the message Just make sure your $email contains a \n. and it should no longer hang.

Upvotes: 0

Related Questions