从 Squeak 或 Pharo 调用 shell 命令

发布于 2024-08-04 12:23:48 字数 148 浏览 2 评论 0原文

如何从 Squeak 和 Pharo 调用 shell 命令?这些环境中是否有类似某些 UNIX 语言中的 system() 函数来运行外部 shell 命令或反引号(不能让它们在这里对编辑器执行操作,但是当您按 " 左侧的键时会得到什么? 1”及以上“TAB”)来捕获命令的输出?

How can you invoke shell commands from Squeak and Pharo? Do these environments have anything in them like the system() function in certain unix languages to run external shell commands, or the backticks (can't make them here do to the editor, but what you get when you push the key left of "1" and above "TAB") to capture the output of commands?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

缱绻入梦 2024-08-11 12:23:48

我认为你可以使用 OSProcess 包来做你想做的事。另外,我认为最好在 squeak-dev 或 pharo 邮件列表中询问。

I think you can use the package OSProcess to do what you want. In addition, I think is better to ask in squeak-dev or pharo mailing list.

独木成林 2024-08-11 12:23:48

在 Squeak 中,您可以使用 CommandShell,但我不知道有什么(如果有的话)可用对于此时的法罗来说。

In Squeak you can use CommandShell, but I don't know what (if anything) is available for Pharo at this time.

眼泪也成诗 2024-08-11 12:23:48

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

Shell support in Squeak/Pharo is pretty limited. There are plans to get this improved; see the Coral project. Your contributions are welcome.

简单爱 2024-08-11 12:23:48

您有两种解决方案:

使用 ProcessWrapper 包。优点:安装快速、简单。缺点:功能有限,仅在 win32 上。

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

You have two solutions:

Use the package ProcessWrapper. Pros: quick and easy install. Cons: limited functionality, only on win32.

Use the package OSProcess/CommandShell. Pros: pretty good functionality (pipes, environment vars, shell-like workspace ...), and cross platform. Cons: must use VMMaker tools to build the external plugin.

深海不蓝 2024-08-11 12:23:48

在 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。

输入图片此处描述

On Windows, there is a wrapper on the Win API allowing you to do this:

| 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 

enter image description here

There are a lot of support for most of what Windows can do with processes in there (env, ...)

So, look in the catalog for OSWindows.

enter image description here

抱着落日 2024-08-11 12:23:48

我正在使用 Windows 10 和 Pharo 6,发现使用 OSProcessOSSubprocess 类不可行(难以安装或 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 ]

可以使用以下命令操作环境变量(尽管它返回值 1 意味着在 Windows 中失败):

   OSEnvironment current setEnv: 'MY_ENVIRONMENT_VARIABLE' value: '1'.

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

OSEnvironment current changeDirectoryTo: myDirectory asFileReference. "--> doesNotUnderstand for Windows"

解决方法是在命令中执行 CD:

result := LibC uniqueInstance system: 
    'cd ', myDirectory, ' && ls > /tmp/output.txt 2>', errors.

I'm using Windows 10 with Pharo 6, and found it unfeasible to use the OSProcess or OSSubprocess classes (hard to install or the latest versions are not supported for Windows).

What does work for me is LibC. You can redirect stderr to a file using 2> inside the command:

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

It's possible to manipulate the environment variables using (although it returns a value of 1 implying failure in Windows):

   OSEnvironment current setEnv: 'MY_ENVIRONMENT_VARIABLE' value: '1'.

However, I was unable to change the current directory:

OSEnvironment current changeDirectoryTo: myDirectory asFileReference. "--> doesNotUnderstand for Windows"

The workaround is to do CD within the command:

result := LibC uniqueInstance system: 
    'cd ', myDirectory, ' && ls > /tmp/output.txt 2>', errors.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文