Hi All,

I am using a python system command to execute a C++ executable file which takes certain binary input.

For example:
C++ exe name is "Test"
"Test" takes the following input . '\x02\xfa\xcbQH\x00'
command = '/opt/etc/Test %s' % ('\x02\xfa\xcbQH\x00')
system command I am using is : os.popen(command)

When this command is executed I get an error message: "TypeError: 'popen() argument 1 must be string without null bytes, not 'str'"

Is there some way I can execute this using system command without getting the above error

Thanks

Recommended Answers

All 3 Replies

Maybe try the exec* family functions:
http://www.python.org/doc/current/lib/os-process.html

Also, the subprocess module is said to handle such things better, to give you the result of your command,etc...


My suggestion: create a batch file and enter your 'Test.exe hex_string' and pause, and run the script from python, in case you can't work out the error...I think the concatenation for your command is the faulty element...try adding an '\0' end of string at the end even, maybe it'll be interpreted differently ....

I'll try and make a similar executable to see what I can change to make it work...

It seems that no zero byte is accepted in a command...How do you pass your argument to Test.exe outside python? Using \x02...?

And never mind my end of string, it's also a null byte....but even your last 0x00 annoys it, so must find a way to pass zeroes...

Hey Tzushky,

Thanks for your reply!!

Test.exe is a C++ exe. If I run it from command line I sipmply give:

./test "\x02\xfa\xcbQH\x00"

It works perfectly fine.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.