TypeError: must be string without null bytes, not str in os.system()
<p>I am trying to write a python code which executes a C executable using the following line </p>

<pre><code>os.system("./a.out \"%s\"" % payload)
</code></pre>

<p>where ./a.out is a C executable, and payload is a string (without spaces) given as command line argument. (The link is <a href="http://codearcana.com/posts/2013/05/28/introduction-to-return-oriented-programming-rop.html" rel="nofollow">this</a>. I am trying to follow example under section chaining functions)
<br> Now I have written another C code but it takes 3 command line arguments. So my string should be arg[1] + " " + arg[2] + " " + payloadString. 
(The c code is converting the arg[1] and arg[2] into integer to use it in its functions). Here is the snippet of my python code:</p>

<pre><code>p = "10 "  #arg[1]
p += "10 " #arg[2]
p += "string without spaces which I need as payload" #arg[3]
os.system("./a.out \"%s\"" % p)
</code></pre>

<p><br> where ./a.out is executable of my C code which takes 3 command line arguments. When I run the python code I get error:</p>

<pre><code>Traceback (most recent call last):
File "this_file.py", line XX, in &lt;module&gt;
os.system("./a.out \"%s\"" % p)
TypeError: must be string without null bytes, not str
</code></pre>

<p><br>Can anyone help me?
<br>P.S. I am new to python. Similar questions were there in stack overflow, but I am not sure how to use their answers to solve my problem.</p>

<p>Put an <code>r</code> in the <code>os.system</code> call. </p>

<pre><code>os.system(r"./a.out \"%s\"" % p)
</code></pre>

python string