我有一个python程序,它创建一个bash命令,然后在中使用它子流程调用(命令)
我想给它发一个有空格的文件位置。你知道吗
import subprocess
command = ["mkdir","/home/matt/Desktop/this"]
command[1] += "\\ is"
subprocess.call(command)
但当它被子进程使用时,它将成为一个名为 这是
这是完整的代码
import pyxhook
import subprocess
command = [""]
isActive = False
element = 0
isSpace = False
def OnKeyPress(event):
global command
global isActive
global element
global isSpace
if event.Ascii == 96:
if isActive == False:
isActive = True
elif isActive == True:
subprocess.call(command)
command = [""]
element = 0
isActive = False
elif isActive == True:
if event.Ascii == 32:
if isSpace == False:
command.append("")
element += 1
else:
command[element] += " "
isSpace = False
elif event.Key == "BackSpace":
command[element] = command[element][:-1]
elif event.Key == "slash":
command[element] += "/"
elif event.Key == "Shift_L" :
command = command
elif event.Key =="Shift_R":
command = command
elif event.Key == "backslash":
isSpace = True
command[element] += "\\"
else:
command[element] += (event.Key)
#instantiate HookManager class
new_hook=pyxhook.HookManager()
#listen to all keystrokes
new_hook.KeyDown=OnKeyPress
#hook the keyboard
new_hook.HookKeyboard()
#start the session
new_hook.start()
谢谢你的帮助
使用子流程时,不需要使用\
保持简单:
如果您的Python早于3.2,请删除
exist_ok=True
。你知道吗请注意您的命令列表以及如何附加内容:
相关问题 更多 >
编程相关推荐