macos - CodeRunner 4.0.3 (Mac 软件) - 如何在终端窗口中执行程序?
问题描述
我在 Mac 上使用 CodeRunner,它是用于多种编程语言的编程 IDE,而不是 Code Runner 或 Visual Studio!
当我执行一个程序时,输入和输出将显示在这个 IDE 中,而不是在外部终端窗口中。
问题是当我将光标设置到屏幕上的特定位置时,它不会正确显示。只有当我打开终端窗口并从那里启动程序时,输入和输出才会显示在正确的位置。
有没有办法直接从 CodeRunner 打开一个外部终端窗口并在那里运行程序?程序完成后我必须手动关闭此窗口是可以的。
解决方案
好的,所以我终于解决了这个问题!步骤: 打开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
将此文件保存在您正在编码的文件夹中/或在执行时提供路径。这看起来像这样:
我将它保存在/Users/aayush/Downloads
文件夹中automated_run
。此脚本编辑器应用程序将此脚本另存为automated_run.scpt
.
现在打开CodeRunner App
。选择Run Settings...
,现在复制Run Command
前面字段中写的命令$filename
。[例如,如果我在 shell 脚本中编码,那么我将从bash
命令中复制bash $filename
;对于python,我python3
将从python3 $filename
]
复制
然后打开脚本编辑器并查看line number 6
并将您的命令粘贴到"bash "
。在这里,我在 shell 脚本中进行编码,以便根据我的要求,我在这里使用了 'bash'。然后in CodeRunner
,粘贴此代码代替run command
in Run Setting...
:
osascript automated_run.scpt $filename $PWD
现在看起来像这样:
现在您有两个选择:您可以将此运行命令设置为默认值,也可以将其用作临时命令。那是你的选择。现在关闭这个窗口。并运行任何示例程序来检查我们刚刚实现的这个功能。让我们运行示例程序:我制作了一个名为的示例文件helloaayush.sh
并将其存储在/Users/aayush/Downloads
现在按下Run
按钮后:将打开一个新的终端窗口,您的代码输出将在那里可见。
让我知道是否有不清楚的地方:)
推荐阅读
- android - 运行 Android 模拟器的问题
- swift - “使用未解析的标识符'vImage_Buffer'”的错误消息
- node.js - Loopback - 使用远程方法下载 pdf
- c# - 更新关于重复的字段 IEnumerable c# EF
- mysql - 数据库中的错误(MySQL)
- ruby - 未定义的方法,但我已经明确定义了吗?
- swift - MacOS SpriteKit - 当用户调整窗口大小时调整 UI 大小
- python - 如何预处理特征值是数字范围的序数特征并相应地对它们进行排名或编码
- html - 更改数据表语言时如何避免闪烁或闪烁?
- c++ - 为什么 VideoCapture 在成员函数中不起作用?