Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I would like to enter an phone number with raw_input and use this variable in my bash command for sending a message. I don't know how to set the variable $Phonenumber. Without the RAW Input, it works like a charm. I use Python 2.7.

import os

Phonenumber = raw_input("Number?)

os.system("yowsup-cli demos --login PHONE:PASSWORD= --send '$Phonenumber' 'MESSAGE'")
share|improve this question
up vote 2 down vote accepted

If you want to stick with using os.system to make your calls, you can just format the command you pass to it:

import os
phone_number = raw_input("Number?")
os.system("yowsup-cli demos --login PHONE:PASSWORD= --send '{0}' 'MESSAGE'".format(phone_number))


However, chepner brings up a good point in his answer. You should really be using the subprocess module for things like this, as it is a much more flexible tool. To get the same behavior using subprocess, just pass a list to subprocess.call with the elements being all the space separated segments of your call:

import subprocess
phone_number = raw_input("Number?")
subprocess.call(["yowsup-cli", "demos", "--login" "PHONE:PASSWORD=", "--send", phone_number, "MESSAGE"])

You can check out more on subprocess here.

share|improve this answer
    
This works! Thank you for your help! – Jesse kraal Apr 23 at 21:14

Use subprocess instead; among other features, it makes quoting much easier.

import subprocess

phone_number = raw_input("Number?")

subprocess.call(["yowsup-cli", "demos", "--login", "PHONE:PASSWORD=",
                 "--send", phone_number, "MESSAGE"])
share|improve this answer
    
subprocess is the better approach - and replaces popen (which is deprecated) ++ – cgseller Apr 24 at 15:19

use:

os.system("yowsup-cli demos --login PHONE:PASSWORD= --send '%d' 'MESSAGE'" % Phonenumber)
share|improve this answer
    
The method of Jake works. But with your solution I get an error (Thanks anyway): Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: %d format: a number is required, not str – Jesse kraal Apr 23 at 21:15
    
Replace the %d with %s – cdarke Apr 23 at 22:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.