PDA

View Full Version : Python: TypeError: system() argument 1 must be string without null bytes, not str



dchurch24
April 28th, 2009, 09:10 PM
Hi all,

I can't seem to find my way around this, I have googled and searched here, but although plenty of people seemingly have the same issue, there appears to be no answer to it.

If I run this line:

os.system("echo -e '\xff\x01\x01' > /dev/ttyUSB0")

The echo executes as it should, but if I run this one (with x00 instead of x01):

os.system("echo -e '\xff\x01\x00' > /dev/ttyUSB0")

I get this error:

TypeError: system() argument 1 must be string without null bytes, not str

I have tried changing the last digit to a string etc... but this happens all the time the last digit in the quotes is not 0.

croto
April 29th, 2009, 01:35 AM
I guess the escaped characters are being interpreted by python. I would try:


os.system(r"echo -e '\xff\x01\x01' > /dev/ttyUSB0")

to prevent python to interpret the escape characters.

nebffa
September 11th, 2012, 12:40 AM
I guess the escaped characters are being interpreted by python. I would try:


os.system(r"echo -e '\xff\x01\x01' > /dev/ttyUSB0")

to prevent python to interpret the escape characters.

Hi, I made a new account just to say that this worked for me (feedback is essential for people on google looking for solutions).


Thanks

Bachstelze
September 11th, 2012, 07:03 AM
Why on Earth would you use system() for that?