Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I wrote a simple program named b.c to call dir in Windows 10 cmd via C.

This is what the script looks like:

#include <stdlib.h>

int main()
{
    system("dir");
    return 0;
}

I typed this in cmd

gcc b.c
b

but it returns

J:fundamental of C programming>b
'b' is not recognized as an internal or external command, operable program or batch file.

This is how I add path

enter image description here

I don't think it is path matter.

So how can I fix it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
122 views
Welcome To Ask or Share your Answers For Others

1 Answer

You need to run

gcc b.c -o b.exe

Without -o option it'll use the default output executable name which is a.exe on Windows and a.out on *nix systems. You can easily see the a.exe with the dir command

-o file

  • Place output in file file. This applies to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.

  • If -o is not specified, the default is to put an executable file in a.out, the object file for source.suffix in source.o, its assembler file in source.s, a precompiled header file in source.suffix.gch, and all preprocessed C source on standard output.

https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html

For more information read Determining C executable name

Of course you can also run a instead of b


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...