sublime 3控制台交互程序的输出
Output of interactive program on sublime 3 console
我正在学习使用 sublime3 文本编辑器编写 C 程序,我有两个不同的 sublime 构建版本
此构建在 CMD 控制台上输出其执行;
> {
"cmd": ["gcc", "$file_name", "-o", "${file_base_name}.exe", "&&", "start", "cmd", "/k", "$file_base_name"],
"selector": "source.c",
"working_dir": "${file_path}",
"shell": true
}
而另一个构建在 sublime 控制台上输出它的执行
> {
"cmd": ["gcc", "$file_name", "-o", "$file_base_name"],
"selector": "source.c",
"working_dir": "${file_path}",
"variants":
[
{
"name": "Run",
"cmd": ["gcc","${file}", "-o", "$file_base_name", "&&", "$file_path/$file_base_name"],
"shell":true
}
]
}
我更喜欢第二个版本,但它只有在你将它用于 运行 非交互式程序时才有效,例如 "Hello world"
程序,当我将它用于 运行 时它会给我错误消息像这样的简单交互程序:
#include <stdio.h>
#include <float.h>
// variable declaration;
int main()
{
float a,b,sum;
printf("Enter value of a\n");
// for float u use "f" instead of d
scanf("%f", &a);
printf("Enter value of b\n");
scanf("%f",&b);
sum=a+b;
printf("The sum of %f and %f = %f\n",a,b,sum);
return 0;
}
错误信息:
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe:
cannot open output file addition.exe: Permission denied collect2.exe:
error: ld returned 1 exit status [Finished in 0.3s]
我想知道我是否可以在 sublime 控制台上执行交互式程序,或者我需要对我的 sublime 构建做些什么。
简短版本:不,您不能 运行 Sublime 中的交互式程序(并与之交互)。
来自 linker 的错误消息告诉您它想要 create/modify 文件 addition.exe
但不允许这样做,因为操作系统(在此case windows) 告诉它不能。
其根本原因是 windows 不会让您 delete/modify 当前正在使用的文件,在这种情况下意味着它现在 运行ning。
要触及问题的核心,运行 直接在 sublime 中创建交互式程序是不可能的;或者更确切地说,您可以 运行 这样的程序,但在控制台中的输入与您正在 运行 的程序之间没有任何联系。
这意味着当您 运行 程序无法与其交互时,它仍然 运行 等待您输入内容。然后,当您修改代码并尝试再次构建和 运行 时,您会收到此处看到的错误,因为可执行文件仍然是 运行ning,无法修改。在这种情况下,您可以取消构建以停止 运行ning 程序。
为了 运行 这样的程序,你需要在 Sublime 之外 运行 它,这样你就可以与它交互(或者使用一个为你做这个的构建系统,比如你的第一个例子)。
也可以使用 Terminus 包构建交互式构建系统。自述文件包含有关如何执行此操作的文档,包括 link 到概述该过程的教程视频。
我正在学习使用 sublime3 文本编辑器编写 C 程序,我有两个不同的 sublime 构建版本 此构建在 CMD 控制台上输出其执行;
> {
"cmd": ["gcc", "$file_name", "-o", "${file_base_name}.exe", "&&", "start", "cmd", "/k", "$file_base_name"],
"selector": "source.c",
"working_dir": "${file_path}",
"shell": true
}
而另一个构建在 sublime 控制台上输出它的执行
> {
"cmd": ["gcc", "$file_name", "-o", "$file_base_name"],
"selector": "source.c",
"working_dir": "${file_path}",
"variants":
[
{
"name": "Run",
"cmd": ["gcc","${file}", "-o", "$file_base_name", "&&", "$file_path/$file_base_name"],
"shell":true
}
]
}
我更喜欢第二个版本,但它只有在你将它用于 运行 非交互式程序时才有效,例如 "Hello world"
程序,当我将它用于 运行 时它会给我错误消息像这样的简单交互程序:
#include <stdio.h>
#include <float.h>
// variable declaration;
int main()
{
float a,b,sum;
printf("Enter value of a\n");
// for float u use "f" instead of d
scanf("%f", &a);
printf("Enter value of b\n");
scanf("%f",&b);
sum=a+b;
printf("The sum of %f and %f = %f\n",a,b,sum);
return 0;
}
错误信息:
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot open output file addition.exe: Permission denied collect2.exe: error: ld returned 1 exit status [Finished in 0.3s]
我想知道我是否可以在 sublime 控制台上执行交互式程序,或者我需要对我的 sublime 构建做些什么。
简短版本:不,您不能 运行 Sublime 中的交互式程序(并与之交互)。
来自 linker 的错误消息告诉您它想要 create/modify 文件 addition.exe
但不允许这样做,因为操作系统(在此case windows) 告诉它不能。
其根本原因是 windows 不会让您 delete/modify 当前正在使用的文件,在这种情况下意味着它现在 运行ning。
要触及问题的核心,运行 直接在 sublime 中创建交互式程序是不可能的;或者更确切地说,您可以 运行 这样的程序,但在控制台中的输入与您正在 运行 的程序之间没有任何联系。
这意味着当您 运行 程序无法与其交互时,它仍然 运行 等待您输入内容。然后,当您修改代码并尝试再次构建和 运行 时,您会收到此处看到的错误,因为可执行文件仍然是 运行ning,无法修改。在这种情况下,您可以取消构建以停止 运行ning 程序。
为了 运行 这样的程序,你需要在 Sublime 之外 运行 它,这样你就可以与它交互(或者使用一个为你做这个的构建系统,比如你的第一个例子)。
也可以使用 Terminus 包构建交互式构建系统。自述文件包含有关如何执行此操作的文档,包括 link 到概述该过程的教程视频。