0

If I type the following command into the terminal, it works and a message "test" is sent.

 sudo echo "test" | sendxmpp -t -u doorbellding -o gmail.com in06khattab 

I wanted to execute this command in Python, but instead of test it would a variable containing the data and time

This is what I have tried, but they all fail.

message="Ding Dong at "+strftime("%l:%M %p on %d-%m-%Y") os.system('sudo echo '+message+' | sendxmpp -t -u doorbellding -o gmail.com in06khattab') #send hangouts message 

enter image description here

os.system('sudo echo "test" | sendxmpp -t -u doorbellding -o gmail.com in06khattab') 

enter image description here

3
  • To be clear, you don't want a shell, and you don't need echo; just run the sendxmpp command with subprocess.Popen, with stdin=subprocess.PIPE, and you can feed it the data directly. Commented Jul 4, 2018 at 0:49
  • I tried, I got the following output. OSError: [Errno 2] No such file or directory prntscr.com/k291y2 Commented Jul 4, 2018 at 0:52
  • That is not at all what the other answer or my comment suggests. You passed a string, not a list, intercepted stdout, not stdin, didn't pass a thing to the subprocess with communicate, etc. Take the time to learn subprocess properly; yes it's more work up front, but it's safer, more stable, and more powerful. Commented Jul 4, 2018 at 0:55

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.