问题描述
在Windows 7中,当我在SWI Prolog中使用process_create / 3打开Notepad.exe等应用程序时,记事本打开。但是,它不适用于使用命令提示符的应用程序。例如,当我试图打开命令提示符窗口,使用:
main: - process_create('C:\ \WINDOWS\\system32\\cmd.exe',[],[])。
它提供
错误:处理c:\windows\system32\cmd.exe:退出状态:1
同样,当尝试打开powershell.exe时,它也不工作。
任何帮助都非常感谢。 / div>
要启动单独的控制台窗口:
? - process_create(path(cmd),['/ c ','start','cmd'],[])。
或更短(但我不知道这是怎么移植的):
? - process_create(path(cmd),['/ c','start'],[])。
或者这样(从SWI-Prolog源代码获取的想法):
? - getenv('COMSPEC',CMD),process_create(CMD,['/ c','start'],[])。
要启动具有3个参数的外部BAT命令:
? - process_create(
path(cmd),
['/ c','start','cmd','/ c' c:\\test\\test.bat','arg1','arg2','arg3'],
[])。
重要说明:理论上,您可以将所有这些参数作为一个字符串,例如。 '/ c start cmd ...'
而不是字符串列表,但奇怪的事情可能发生在更复杂的情况下。在我的例子中,SWI-Prolog 7.2.3在结尾添加了单引号或单双引号,因此传递给批处理脚本的最后一个参数不是 arg3
,而是 arg3'
或 arg3
。
On Windows 7, when I used process_create/3 in SWI Prolog to open an application like Notepad.exe, the notepad opens. However, it doesn't work for applications that use command prompt. As an example, when I tried to open the command prompt window, using:
main :- process_create('C:\\WINDOWS\\system32\\cmd.exe',[] ,[]).
which gives an
ERROR: Process "c:\windows\system32\cmd.exe": exit status: 1
Similarly, when trying it to open powershell.exe, it doesn't work either. the console just hangs, without displaying an error.
Any help is greatly appreciated.
To start a separate console window:
?- process_create(path(cmd), ['/c', 'start', 'cmd'], []).
Or even shorter (but I don't know how portable this is):
?- process_create(path(cmd), ['/c', 'start'], []).
Or this way (idea taken from SWI-Prolog source code):
?- getenv('COMSPEC', CMD), process_create(CMD, ['/c', 'start'], []).
To start an external BAT command with 3 arguments:
?- process_create(
path(cmd),
['/c', 'start', 'cmd', '/c', 'c:\\test\\test.bat', 'arg1', 'arg2', 'arg3'],
[]).
Important note: theoretically you could pass all this arguments as one string, eg. '/c start cmd ...'
instead of list of strings but strange things may happen in more sophisticated cases. In my case SWI-Prolog 7.2.3 added single quote or single double quote at the end, so the last argument passed to batch script was not arg3
but arg3'
or arg3"
.
这篇关于在SWI Prolog中使用process_create / 3使用命令提示符或shell时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!