In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "how C language uses system to call the command line of the system". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
System, as its name implies, invokes the system command line, enters it as a string, and then outputs the string to the command line for execution.
To test its features, make a Mini Program:
/ / system.c#include#include#includeint main () {char cmd [100]; while (1) {printf ("input code:"); gets (cmd); if (strcmp (cmd, "exit") = = 0) break; / / exit system (cmd) when entering exit;} return 0;}
And then start.
> gcc system.c > a.exeinput code: asdfasdf'asdfasdf' is not an internal or external command, nor is it a runnable program or batch file. Input code: date current date: 2021-12-19 Sunday enter a new date: (year, month, day) input code: date current date: 2021-12-19 Sunday enter a new date: (year, month, day) input code: HELP for more information about a command, type the HELP command name ASSOC to display or modify the file extension association. ATTRIB displays or changes file properties. BREAK sets or clears extended CTRL+C checks. BCDEDIT sets properties in the startup database to control startup loading. # because it's too long and the result is the same as typing HELP on the command line, the details of the tool are omitted here, see the command line reference in the online help. Input code: exit # exit
With system, you can make an enhanced command line.
In addition to the commands provided by these terminals, you may also need some custom statements, which are stored in the environment variables, and getenv can get the environment variables corresponding to the names.
Char * getenv (const char * name)
For example:
# include # include int main () {printf ("PATH:% s\ n", getenv ("PATH")); return 0;}
The running results are as follows:
E:\ Documents\ 00\ 1220 > a.exe
PATH: C:\ Program Files\ Microsoft\ jdk-11.0.12.7-hotspot\ bin;C:\ Python310\ Scripts\; C:\ Python310\; C:\ Program Files\ Common Files\ Oracle\ Java\ javapath;D:\ CS\ ImageMagick; (x86)\ Common Files\ Intel\ Shared
....
This is the end of the content of "how C language uses system to call the system command line". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.