首页 > 解决方案 > CodeRunner 4.0.3 (Mac 软件) - 如何在终端窗口中执行程序?

问题描述

我在 Mac 上使用 CodeRunner,它是用于多种编程语言的编程 IDE,而不是 Code Runner 或 Visual Studio!

当我执行一个程序时,输入和输出将显示在这个 IDE 中,而不是在外部终端窗口中。

问题是当我将光标设置到屏幕上的特定位置时,它不会正确显示。只有当我打开终端窗口并从那里启动程序时,输入和输出才会显示在正确的位置。

有没有办法直接从 CodeRunner 打开一个外部终端窗口并在那里运行程序?程序完成后我必须手动关闭此窗口是可以的。

标签: macoscoderunner

解决方案


好的,所以我终于解决了这个问题!步骤: 打开Script Editor应用程序。创建新脚本并粘贴此代码:

on run argv
    tell application "Terminal" to activate
    tell application "Terminal" to do script "cd ~" in selected tab of the front window
    tell application "Terminal" to do script "cd " & item 2 of argv in selected tab of the front window
    tell application "Terminal" to do script "clear" in selected tab of the front window
    tell application "Terminal" to do script "bash " & item 1 of argv in selected tab of the front window
end run

将此文件保存在您正在编码的文件夹中/或在执行时提供路径。这看起来像这样: MacOS 中的脚本编辑器应用程序 我将它保存在/Users/aayush/Downloads文件夹中automated_run。此脚本编辑器应用程序将此脚本另存为automated_run.scpt.

现在打开CodeRunner App。选择Run Settings...,现在复制Run Command前面字段中写的命令$filename。[例如,如果我在 shell 脚本中编码,那么我将从bash 命令中复制bash $filename;对于python,我python3 将从python3 $filename] 复制从 coderunner 中的运行命令复制命令 然后打开脚本编辑器并查看line number 6并将您的命令粘贴到"bash "。在这里,我在 shell 脚本中进行编码,以便根据我的要求,我在这里使用了 'bash'。然后in CodeRunner,粘贴此代码代替run commandin Run Setting...

osascript automated_run.scpt $filename $PWD

现在看起来像这样: 在 coderunner 运行设置中运行命令... 现在您有两个选择:您可以将此运行命令设置为默认值,也可以将其用作临时命令。那是你的选择。现在关闭这个窗口。并运行任何示例程序来检查我们刚刚实现的这个功能。让我们运行示例程序:我制作了一个名为的示例文件helloaayush.sh并将其存储在/Users/aayush/Downloads CodeRunner 文件 helloaayush.sh 截图

现在按下Run按钮后:将打开一个新的终端窗口,您的代码输出将在那里可见。 显示代码输出的终端窗口

让我知道是否有不清楚的地方:)


推荐阅读