简体   繁体   English

TypeError:必须是不包含空字节的字符串,在os.system()中不能为str

[英]TypeError: must be string without null bytes, not str in os.system()

I am trying to write a python code which executes a C executable using the following line 我正在尝试编写使用以下行执行C可执行文件的python代码

os.system("./a.out \"%s\"" % payload)

where ./a.out is a C executable, and payload is a string (without spaces) given as command line argument. 其中./a.out是C可执行文件,有效负载是作为命令行参数给出的字符串(不带空格)。 (The link is this . I am trying to follow example under section chaining functions) (链接是这个 。我试图按照节链接功能下的示例进行操作)
Now I have written another C code but it takes 3 command line arguments. 现在,我编写了另一个C代码,但是它需要3个命令行参数。 So my string should be arg[1] + " " + arg[2] + " " + payloadString. 所以我的字符串应该是arg [1] +“” + arg [2] +“” + payloadString。 (The c code is converting the arg[1] and arg[2] into integer to use it in its functions). (C代码将arg [1]和arg [2]转换为整数以在其函数中使用)。 Here is the snippet of my python code: 这是我的python代码的片段:

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)


where ./a.out is executable of my C code which takes 3 command line arguments. 其中./a.out是我的C代码的可执行文件,它带有3个命令行参数。 When I run the python code I get error: 当我运行python代码时,出现错误:

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


Can anyone help me? 谁能帮我?
PS I am new to python. PS我是python的新手。 Similar questions were there in stack overflow, but I am not sure how to use their answers to solve my problem. 堆栈溢出中也存在类似的问题,但是我不确定如何使用他们的答案来解决我的问题。

os.system调用中放入r

os.system(r"./a.out \"%s\"" % p)

Why don't you use call for this purpose. 您为什么不为此目的使用通话。 I guess it will do the work You can provide the arguments in the list Example: 我想它将完成工作。您可以在列表示例中提供参数:

from subprocess import call
call(["./a.out","10","10","string without spaces which I need as payload"])

here in your case it is equivalent to 在你的情况下,这相当于

call(["./a.out",arg[0],arg[1],arg[2]])

I think this should work 我认为这应该工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:必须是不包含空字节的字符串,而不是str - TypeError: must be string without null bytes, not str TypeError:file()参数1必须是没有NULL字节的编码字符串,而不是str - TypeError: file() argument 1 must be encoded string without NULL bytes, not str python TypeError:必须是没有 NULL 字节的编码字符串,而不是 str - docker iron requirements.txt - python TypeError: must be encoded string without NULL bytes, not str - docker iron requirements.txt 训练 &#39;\\x00&#39; s 和 TypeError: stat() 参数 1 必须是没有空字节的编码字符串,而不是 str - Training '\x00' s and TypeError: stat() argument 1 must be encoded string without null bytes, not str TypeError:必须为str,而不是字节 - TypeError: must be str, not bytes “必须是没有 null 字节的字符串”或“无法将 str 连接到字节”在命令行上传递有效负载 - “must be a string without null bytes” or “can't concat str to bytes” passing a payload on a command line TypeError:必须是str,而不是字节Error - TypeError: must be str, not bytes Error 在 Python3 中解码字节字符串时出错 [TypeError: must be str, not bytes] - Error decoding byte string in Python3 [TypeError: must be str, not bytes] TypeError:compile()期望字符串,不带空字节 - TypeError: compile() expected string without null bytes 没有输出的Python os.system - Python os.system without the output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM