1, C + + call DOS command
Writing a C + + program in a Microsoft Visual C + + environment can include a header file <stdlib.h> then call the system () function in the main function body to invoke the DOS command.
For example: If you want the program to stop using System ("PAUSE") in a certain place, you can pause it;
System ("CLS"), can clear screen;
System ("DIR C:"), you can query C disk;
System ("Start Regedit.exe"); Open the Registry;
System ("NET user"), view local user groups, and so on ...
2. How to invoke the execution bat file or exe file in the program
In C #
1. Execute Batch document System.Diagnostics.Process.Start (path);
Path for file paths
2, modify the batch process file
FileStream afile = new FileStream (FilePath, FileMode.OpenOrCreate);
temp = ""; Content in a batch file
Chardata = temp. ToCharArray ();
Encoder e = Encoding.UTF8.GetEncoder ();
E.getbytes (chardata, 0, Chardata.length, bydata, 0, true); Converts a character array to a byte-type array
Afile.write (bydata, 0, bydata.length);
Afile.close ();
In C
System ("*.bat");
System ("*.exe");
#include <process.h>
It does not have to be in the same directory, as long as you want to execute the. bat file
1. In the various directories of the system path variable (known as path execution at the command prompt)
2. In the directory where the program is located
3. The first two can be directly by the way upstairs, otherwise, you must specify the absolute path (e.g.: D:\prog\test.exe) or relative path (e.g.: \sub\subsub\test2.exe).
Note that ' \ ' needs to be represented by the escape character ' \ \ ' (Or try "/").
--------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------
Take C For example, the code is as follows:
#include "stdio.h"
#include "stdlib.h"
#include <process.h>
void Main ()
{
system ("A.bat") );
System ("PAUSE");
}
A.bat's Code
Type *.txt > A
In the file A, modify the suffix named A.txt
Or use B.bat code directly (B.bat to change the suffix name of file a)
@echo off
Ren a a.txt
Combined, you can write the following. bat code:
Type *.txt > A
@echo off
ren a a.txt