我正在使用subprocess.Popen
来启动一个新程序,该程序需要来自stdin的int数据。
proc = Popen('command', shell=False,stdout=PIPE, stdin=PIPE, stderr=STDOUT)
proc.communicate(1)
错误
TypeError: 'int' object is unsubscriptable
我可以通过其他方式启动新程序并传递int数据吗?
答案 0 :(得分:0)
答案 1 :(得分:0)
city.select2()
的参数必须是Popen.communicate()
或bytes
对象。这应该适用于Python 2.x和3.x:
str
或使用变量:
proc.communicate(b'1')
为了完整起见,要发送一个实际的整数而不是它的ASCIIfication,你可以这样做:
proc.communicate(str(myint).encode())