ValueError:在使用os.popen().read()时嵌入空字节



我试图管道一些行与图标的利润,但我得到这个错误,我不明白为什么

def show_podcasts(f):
podcasts_list = ""
with open(f,"r") as podcasts:
for line in podcasts:
episode_title = " ".join(line.split(" ")[:-2])
found = False
for pic in os.listdir("images"):
if os.path.isfile(os.path.join("images",pic)):
if pic.startswith(episode_title):
found = True
podcasts_list += episode_title + "x00iconx1f" + pic + "n"
if not found:
podcasts_list += episode_title + "n"
print(podcasts_list)
selected_podcast = os.popen("(cat << EOFn" + podcasts_list + "EOFn)| rofi -dmenu -p 'enter the podcast you are looking for'").read()

,这是错误


Traceback (most recent call last):
File "/home/javier/ssd/dev/python/pod-rofi/main.py", line 91, in <module>
main()
File "/home/javier/ssd/dev/python/pod-rofi/main.py", line 84, in main
show_podcasts("podcasts")
File "/home/javier/ssd/dev/python/pod-rofi/main.py", line 77, in show_podcasts
selected_podcast = os.popen("(cat << EOFn" + podcasts_list + "EOFn)| rofi -dmenu -p 'enter the podcast you are looking for'").read()
File "/usr/lib/python3.10/os.py", line 985, in popen
proc = subprocess.Popen(cmd,
File "/usr/lib/python3.10/subprocess.py", line 966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.10/subprocess.py", line 1775, in _execute_child
self.pid = _posixsubprocess.fork_exec(
ValueError: embedded null byte

我不明白你到底想做什么,但如果我解释错误,希望它有所帮助。

运行程序涉及系统调用,接口遵循c语言规则,字符串(在本例中是命令)以空字节结束。该规则意味着空字节不能是字符之一。

但是这里得到插入的空字节:

podcasts_list += episode_title + "x00iconx1f" + ....
#                                 ^^^^

相关内容

  • 没有找到相关文章

最新更新