Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Smalltalk 从Squeak或Pharo调用shell命令_Smalltalk_Squeak_Pharo - Fatal编程技术网

Smalltalk 从Squeak或Pharo调用shell命令

Smalltalk 从Squeak或Pharo调用shell命令,smalltalk,squeak,pharo,Smalltalk,Squeak,Pharo,如何从Squeak和Pharo调用shell命令?这些环境中是否有任何东西,比如某些unix语言中运行外部shell命令的system()函数,或用于捕获命令输出的背景标记(在这里它们不能对编辑器起作用,但当您按下“1”左键和“TAB”上方的键时会得到什么?在Squeak中,您可以使用,但我不知道是什么(如有的话)现在可供Pharo使用。我认为您可以使用包OSProcess来做您想做的事情。此外,我认为最好在squeak dev或Pharo邮件列表中询问。squeak/Pharo中的Shell支

如何从Squeak和Pharo调用shell命令?这些环境中是否有任何东西,比如某些unix语言中运行外部shell命令的system()函数,或用于捕获命令输出的背景标记(在这里它们不能对编辑器起作用,但当您按下“1”左键和“TAB”上方的键时会得到什么?

在Squeak中,您可以使用,但我不知道是什么(如有的话)现在可供Pharo使用。

我认为您可以使用包OSProcess来做您想做的事情。此外,我认为最好在squeak dev或Pharo邮件列表中询问。

squeak/Pharo中的Shell支持非常有限。有计划对此进行改进;请参阅。欢迎您的贡献。

您有两种解决方案:

使用ProcessWrapper软件包。优点:快速方便地安装。缺点:功能有限,仅在win32上


使用OSProcess/CommandShell软件包。优点:相当好的功能(管道、环境变量、类似shell的工作区…)和跨平台。缺点:必须使用VMMaker工具来构建外部插件。

我正在使用Windows 10和Pharo 6,发现使用
OSProcess
OSSubprocess
类是不可行的(难以安装或Windows不支持最新版本)

对我有效的是LibC。您可以在命令中使用
2>
将stderr重定向到一个文件:

errors := '/tmp/errors.txt'.
result := LibC uniqueInstance system: 
    'echo "Hello World" > /tmp/hello.txt 2>', errors.
result = 0 ifFalse: [ errors asFileReference ]
result := LibC uniqueInstance system: 
    'cd ', myDirectory, ' && ls > /tmp/output.txt 2>', errors.
可以使用操作环境变量(尽管它返回的值为1表示Windows中出现故障):

但是,我无法更改当前目录:

OSEnvironment current changeDirectoryTo: myDirectory asFileReference. "--> doesNotUnderstand for Windows"
解决方法是在命令中执行CD:

errors := '/tmp/errors.txt'.
result := LibC uniqueInstance system: 
    'echo "Hello World" > /tmp/hello.txt 2>', errors.
result = 0 ifFalse: [ errors asFileReference ]
result := LibC uniqueInstance system: 
    'cd ', myDirectory, ' && ls > /tmp/output.txt 2>', errors.

在Windows上,Win API上有一个包装器,允许您执行以下操作:

| sqlPlusExe sqlPlusRunInDir scriptPathString| 

scriptPathString := (FileLocator imageDirectory / 'data' / 'sqlplus' / 'testquit.sql') pathString.

sqlPlusExe :='C:\oraclexe\app\oracle\product\11.2.0\server\bin\sqlplus.exe /nolog @' , scriptPathString.
sqlPlusRunInDir := 'C:\oraclexe\app\oracle\product\11.2.0\server\bin'.

sqlPlusWinProcessInformation := WinProcess 
        createAndWaitForProcess: sqlPlusExe 
        withCurrentDirectory: sqlPlusRunInDir 

Windows可以对其中的进程执行的大部分操作都有很多支持(env,…)

因此,请在目录中查找OSWindows


OSProcess将运行shell命令。只有在需要输出或需要图像中的GUI终端时,才需要CommandShell。