0

你好!

我试图进行 subprocess.call() 将当前驱动器更改为 C: 但它给了我一个 WindowsError 说访问被拒绝。这是完整的错误:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1541, in __call__
    return self.func(*args)
  File "C:\Snake\snake.py", line 18, in open_file
    call("C:")
  File "C:\Python27\lib\subprocess.py", line 168, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\Python27\lib\subprocess.py", line 390, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
    startupinfo)
WindowsError: [Error 5] Access is denied

这是我的代码:

from tkinter import *
from tkinter import filedialog
from subprocess import *
import shutil

root = Tk()
root.title("Snake converter")
def open_file():
    
    filename = filedialog.askopenfilename(filetypes = (("Snake files", "*.sim"),("Python Files", "*.py"),("All files", "*.*")))
    filenametmp = filename + ".tmp"
    print filename + " is being compiled. Please wait..."
    tf = open(filenametmp, "a")
    f = open(filename, "r")
    filecontents = f.read()
    tf.write("from simincmodule import *" + "\n")
    tf.write(filecontents)
    call("C:")
    call("cd C:\Snake\info\Scripts")
    f.close()
    tf.close()
    print "Done compiling " + filename + ". Find the file under /dist/[filename]/[filename].exe"
    
openbutton = Button(root, text = "Open", width = 10, command = open_file)
openbutton.pack()

root.mainloop() 

任何提供的帮助,甚至是建议,都将不胜感激。

提前致谢!

4

0 回答 0