Windows 7上的Windows批处理文件问题

时间:2022-01-19 02:23:38

I have a batch file to compile and link all of my code. It contains the following:

我有一个批处理文件来编译和链接我的所有代码。它包含以下内容:

@echo off
nasm -f aout -o start.o start.asm
gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o main.o main.c
gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o scrn.o scrn.c
ld -T link.ld -o kernel.bin start.o main.o scrn.o
pause

Problem is, when i run it it just prints all this out as text. It's definitely a batch file. it has the .bat file ending, and in notepad++, the syntax for @echo off and pause are being highlighted without being set manually. Is this a windows 7 bug? or am i doing something wrong?

问题是,当我运行它时,它只是将所有这些打印为文本。它绝对是一个批处理文件。它的.bat文件结尾,在notepad ++中,@ echo off和pause的语法正在突出显示而不是手动设置。这是一个Windows 7的错误吗?或者我做错了什么?

2 个解决方案

#1


Are you running from a command line or by double-clicking in Explorer?

您是从命令行运行还是双击资源管理器?

Maybe you have the Edit action set as the default?

也许您将“编辑”操作设置为默认值?

Try right-clicking and selecting Open.

尝试右键单击并选择“打开”。

EDIT: Maybe your line terminators are messed up. Windows expects CRLF.

编辑:也许你的线路终结器搞砸了。 Windows期望CRLF。

In Notepad++:

  • Click View->Show End Of Line.
  • 单击视图 - >显示行尾。

  • If they are not CRLF, click Format->Convert to Windows Format.
  • 如果它们不是CRLF,请单击格式 - >转换为Windows格式。

#2


A simpler example
Windows 7 installed
Using cygwin to get gcc

安装Windows 7的简单示例使用cygwin获取gcc

I used the following batch script:

我使用了以下批处理脚本:

PATH = %PATH%;C:\cygwin\bin;
gcc test.c

on the following c file:

在以下c文件中:

main() {
        printf("hello, world");
}

And it compiled fine.

编译得很好。

My Conclusion
Windows 7 batch scripts work pretty much like in previous versions of windows.

我的结论Windows 7批处理脚本的工作方式与之前版本的Windows非常相似。

Simple things that could trip you up
Gcc is not installed by default on Windows, I suggest either cygwin or mingw
Gcc is not on the PATH by default after you have installed gcc, you can add it to the system's environment variable or add it in your batch script (using something like the first line of the batch script I just used).

简单的事情可能会让你失望Gcc默认情况下没有安装在Windows上,我建议安装gcc后默认情况下cygwin或mingw Gcc不在PATH上,你可以将它添加到系统的环境变量中或添加到你的批处理脚本(使用类似我刚刚使用的批处理脚本的第一行)。

#1


Are you running from a command line or by double-clicking in Explorer?

您是从命令行运行还是双击资源管理器?

Maybe you have the Edit action set as the default?

也许您将“编辑”操作设置为默认值?

Try right-clicking and selecting Open.

尝试右键单击并选择“打开”。

EDIT: Maybe your line terminators are messed up. Windows expects CRLF.

编辑:也许你的线路终结器搞砸了。 Windows期望CRLF。

In Notepad++:

  • Click View->Show End Of Line.
  • 单击视图 - >显示行尾。

  • If they are not CRLF, click Format->Convert to Windows Format.
  • 如果它们不是CRLF,请单击格式 - >转换为Windows格式。

#2


A simpler example
Windows 7 installed
Using cygwin to get gcc

安装Windows 7的简单示例使用cygwin获取gcc

I used the following batch script:

我使用了以下批处理脚本:

PATH = %PATH%;C:\cygwin\bin;
gcc test.c

on the following c file:

在以下c文件中:

main() {
        printf("hello, world");
}

And it compiled fine.

编译得很好。

My Conclusion
Windows 7 batch scripts work pretty much like in previous versions of windows.

我的结论Windows 7批处理脚本的工作方式与之前版本的Windows非常相似。

Simple things that could trip you up
Gcc is not installed by default on Windows, I suggest either cygwin or mingw
Gcc is not on the PATH by default after you have installed gcc, you can add it to the system's environment variable or add it in your batch script (using something like the first line of the batch script I just used).

简单的事情可能会让你失望Gcc默认情况下没有安装在Windows上,我建议安装gcc后默认情况下cygwin或mingw Gcc不在PATH上,你可以将它添加到系统的环境变量中或添加到你的批处理脚本(使用类似我刚刚使用的批处理脚本的第一行)。