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

Hamoudy
  • 559
  • 2
  • 8
  • 24
  • 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. – ShadowRanger Jul 04 '18 at 00:49
  • I tried, I got the following output. OSError: [Errno 2] No such file or directory http://prntscr.com/k291y2 – Hamoudy Jul 04 '18 at 00: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. – ShadowRanger Jul 04 '18 at 00:55

0 Answers0