为什么会出现“无法识别的命令"?错误仅在填充窗口时发生? [英] Why would an "command not recognized" error occur only when a window is populated?

查看:29
本文介绍了为什么会出现“无法识别的命令"?错误仅在填充窗口时发生?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的记录表应用有一个用于创建新的空白记录表的菜单选项.当我打开一个工作表窗口时,我可以毫无问题地打开新窗口,使用 subprocess.Popen() 来做到这一点.

My record sheet app has a menu option for creating a new, blank record sheet. When I open a sheet window, I can open new windows without a problem, using subprocess.Popen() to do it.

但是,在 Windows 下(我还没有在其他操作系统上测试过),如果我打开一个新窗口然后使用打开文件"对话框用文件中的数据填充字段,我将无法再使用创建新窗口.填充后,Windows 会给我

However, under Windows (I haven't tested it on other OSes yet), if I open a new window then use the "open file" dialog to populate the fields with data from a file, I'm no longer able to create new windows. Once it's populated, Windows gives me the

'foo.py' 不是内部或外部命令,可操作程序或批处理文件.

'foo.py' is not recognized as an internal or external command, operable program or batch file.

我不明白什么会导致 Windows 突然无法识别 Popen() 调用.我没有任何代码会以我所知道的任何方式影响它.

I don't understand what would cause Windows to suddenly not recognize the Popen() call. I don't have any code that would affect it in any way that I'm aware of.

推荐答案

从错误消息来看,您似乎需要将foo.py"的完整路径传递给您的 Popen 调用.通常只有foo.py"会在您当前的工作目录中搜索,但我发现这在 Windows 上可能有点不可预测.你的似乎在打开文件对话框中跳来跳去.

From the error message, it looks like you need to pass the full path of "foo.py" to your Popen call. Normally just having "foo.py" will search in your current working directory, but this can be a bit unpredictable on Windows, I have found. Yours seems to be jumping around with the open file dialog.

其次,为了更好的衡量,您似乎需要将 foo.py 作为参数传递给 python.exe 可执行文件,而不是执行 foo.py 本身.同样,我会通过路径指定这一点.

Secondly, just for good measure, it would seem like you would need to pass foo.py as an argument to python.exe executable, rather than executing foo.py itself. Again, I would specify this by path.

为了安全起见,例如:

subprocess.Popen([r'C:\Python2.5\python.exe', r'C:\path\to\foo.py'])

这篇关于为什么会出现“无法识别的命令"?错误仅在填充窗口时发生?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆