[英]Compile and run in Mac Terminal Sublime Text files
I'm working with a Mac and I want to compile and run my C files from the Terminal using a script. 我正在使用Mac,并且想使用脚本从终端编译并运行C文件。 I've found a solution that apparently works in Linux.
我发现了一个显然可以在Linux中运行的解决方案。 Here is the article in Spanish ( http://ayudasprogramacionweb.blogspot.com.es/2013/01/ejecutar-en-terminal-linux-sublime-text.html ).
这是西班牙语文章( http://ayudasprogramacionweb.blogspot.com.es/2013/01/ejecutar-zh-terminal-linux-sublime-text.html )。 It consists in two simple steps:
它包含两个简单步骤:
You create a script in linux to compile and execute the source code in the Terminal and you store it in your Documents folder named as runC.sh. 您在linux中创建一个脚本以在终端中编译和执行源代码,并将其存储在名为runC.sh的Documents文件夹中。
#!/bin/bash gnome-terminal -e "/bin/bash -c 'gcc -Wall $1 -o $2; ./$2; echo; read -p 'Press_enter_to_scape...'; exit; exec /bin/bash'; &"
Through a Sublime Text Build System, you call this script by passing as parameters the name of the source file. 通过Sublime Text Build System,您可以通过传递源文件的名称作为参数来调用此脚本。
{ "cmd": ["~/Documents/runC.sh ${file_name} ${file_base_name}"], "shell": true }
I've tried it in my Mac but as I expected it doesn't work... Could you help me to adapt it for Mac OS please? 我已经在Mac上尝试过了,但是正如我期望的那样,它无法正常工作……您能帮我将其适配于Mac OS吗? I've just started programming and I don't know where to start to fix it... thank you very much!
我才刚刚开始编程,但是不知道从哪里开始修复它……非常感谢!
After days of searching I've finally found a solution! 经过几天的搜索,我终于找到了解决方案! In Mac there is no need of a script, all that you need is the proper Build System.
在Mac中,不需要脚本,您只需要适当的构建系统即可。
This one for C files: 这个用于C文件:
"cmd": ["bash", "-c", "gcc '${file}' -o '${file_path}/${file_base_name}' && open -a Terminal.app '${file_path}/${file_base_name}'"]
And this one for C++ files: 这是C ++文件:
"cmd": ["bash", "-cpp", "g++ '${file}' -o '${file_path}/${file_base_name}' && open -a Terminal.app '${file_path}/${file_base_name}'"]
Now, when I press Cmd+B, a new Terminal window opens and my file runs, and of course it accepts input from the user, which sublime text console doesn't... 现在,当我按Cmd + B时,将打开一个新的“终端”窗口并运行我的文件,并且它当然接受来自用户的输入,而Sublime文本控制台则不会...
Simple and easy! 简单容易! All the credits to this guy: https://stackoverflow.com/a/18562836/4359229
这个家伙的所有功劳: https : //stackoverflow.com/a/18562836/4359229
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.