简体   繁体   English

从SciTE运行时,控制台程序无法正确执行

[英]Console program does not execute correctly when run from SciTE

I'm learning C from a tutorial concurrently with a general programming course. 我正在从与一般编程课程同时进行的教程中学习C。 The course setup advised Windows users to use SciTE, so I did. 课程设置建议Windows用户使用SciTE,所以我做到了。 Possibly because I have Windows 8, I had to edit the SciTE cpp.properties file to get the sample programs to run. 可能是因为我有Windows 8,所以我必须编辑SciTE cpp.properties文件才能运行示例程序。 This is what the make/go section of the properties file looks like: 这是属性文件的make / go部分的样子:

ccopts=-pedantic -Os
cc=g++ $(FileNameExt) -o $(FileName).exe
ccc=gcc $(FileNameExt) -o $(FileName).exe

make.command=make
command.compile.*.c=$(ccc) -std=c99
command.build.*.c=$(make.command)
command.build.*.h=$(make.command)
command.clean.*.c=$(make.command) clean
command.clean.*.h=$(make.command) clean
command.go.*.c=$(FileName)

My problem is that I cannot get this one program to execute in SciTE. 我的问题是我无法在SciTE中执行此程序。 It works fine in PowerShell/cmd but if I try to execute it in SciTE, I don't get the first printout and providing input does nothing. 它在PowerShell / cmd中可以正常工作,但是如果我尝试在SciTE中执行它,则不会得到第一个打印输出,并且提供输入不会执行任何操作。 It also never ends, even if I stop executing. 即使我停止执行,它也永远不会结束。 I have to go into task manager and end the program. 我必须进入任务管理器并结束程序。 I have had this problem before, but that was because I mistyped. 我以前曾遇到过这个问题,但这是因为我输错了。 I don't know what I've mistyped here: 我不知道在这里输错了什么:

#include <stdio.h>
#include <conio.h>

int main(void)
{
    int num1;
    int num2;
    printf("Enter 2 numbers\n");
    scanf("%d%d", &num1, &num2);

    if(num1 == num2) {
        printf("they are equal\n");
    }

    if(num1 < num2) {
        printf("%d is less than %d\n", num1, num2);
        }

    if(num1 > num2) {
        printf("%d is greater than %d\n", num1, num2);
        }

    getch();
}

SciTE's output pane is not a regular console as you would expect - you can not ask for user input in SciTE's output pane. SciTE的输出窗格不是您期望的常规控制台-您无法在SciTE的输出窗格中要求用户输入。

However you can perhaps make use of parameters and slightly change you script to accept parameters instead user input. 但是,您也许可以使用参数,并稍稍更改脚本以接受参数而不是用户输入。

Another option is use of other then default subsystem for go command: 另一个选择是对go命令使用其他而非默认子系统

command.compile.*.c=gcc $(FileNameExt) -o $(FileName).exe
command.go.*.c="$(FileDir)\$(FileName).exe"
command.go.subsystem.*.c=2

You can paste this block at the end of you cpp.properties if you wish to try it. 如果您想尝试,可以将其粘贴在cpp.properties的末尾。 Even more if you would like a Go command that compiles on the fly and executes, append this line to above block: 如果您希望Go命令可以即时编译并执行,甚至更多,请将此行追加到上面的代码块中:

command.go.needs.*.c=gcc $(FileNameExt) -o $(FileName).exe

Side note: You can always terminate running SciTE program with Ctrl+Break or with "Tools > Stop executing" menu command. 旁注:您始终可以通过Ctrl+Break或“工具>停止执行”菜单命令来终止运行SciTE程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM