C # Thinking about the Process class, cf
C # Thinking about the Process class
Here, I will give myself an impression
The program is as follows:
Process p = new Process ();
P. StartInfo. FileName = "cmd.exe"; // set the startup process command
/** Set whether to set standard input/output and standard errors. If these values are set to true
** UseShellExcute must be false */
P. StartInfo. UseShellExcute = false;
P. StartInfo. RedirectStanderInput = true;
P. StartInfo. RedirectStanderOutput = true;
P. StartInfo. RedirectStanderError = true;
P. StartInfo. CreatNoWindows = true;
P. start ();
// Enter the ping command in the Dos window. Set the IP address here.
P. StandardInput. WriteLine ("ping-n 1" + IP );
// Enter the command to exit the window
P .. StandardInput. WriteLine ("Exit ");
/** Use ReadToEnd to read the output and assign it to a string value.
** Note that the ReadToEnd command can be executed only after the called program ends.
** If you put this sentence after the above "Exit", the program will enter an endless loop */
String output = p. StandardOutput. ReadToEnd ();
The main work has been completed, and you can see how to use the input and output of the program to complete some functions.
Here I also wrote an implementation:
Program code
- Using System;
- Using System. Collections. Generic;
- Using System. Linq;
- Using System. Text;
- Using System. Diagnostics;
- Namespace ConsoleApplication1
- {
- Class Program
- {
- Static void Main (string [] args)
- {
- Process process = new Process ();
- String strBatPath = "E:/test. bat ";
- String mess = ExecuteBAT (strBatPath, process );
- Console. WriteLine (mess );
- Console. ReadKey ();
- }
- Private static string ExecuteBAT (string strBatPath, Process pro)
- // File path; the process for executing the bat file and returning the execution result
- {
- String mess = "";
- Try
- {
- Pro. StartInfo. UseShellExecute = true;
- // StrBatPath is the bat file path
- Pro. StartInfo. FileName = strBatPath;
- Pro. StartInfo. CreateNoWindow = true;
- If (pro. Start ())
- {
- // Write a log file
- Mess = DateTime. Now. ToLongDateString () + "" + strBatPath + "executed successfully ";
- }
- Else
- {
- Mess = string. Format ("failed to execute {0}.", strBatPath );
- }
- }
- Catch (Exception ex)
- {
- Mess = ex. Message;
- }
- Finally
- {
- Pro. Close ();
- }
- Return mess;
- }
- }
- }
Now I am writing a C # method for reading files.
C # code
- Public static void printFile (string strFileName)
- {
- StreamReader srd;
- Try
- {
- Srd = File. OpenText (strFileName );
- }
- Catch (Exception e)
- {
- Console. WriteLine (e. Message );
- Console. WriteLine ("File not read ");
- Return;
- }
- While (srd. Peek ()! =-1)
- {
- String str = srd. ReadLine ();
- Console. WriteLine (str );
- }
- Console. WriteLine ("End of read ");
- Srd. Close ();
- }
- Public static void InputFile (string strFileName)
- {
- StreamWriter swt;
- Try
- {
- Swt = File. CreateText (strFileName );
- }
- Catch (Exception e)
- {
- Console. WriteLine (e. Message );
- Console. WriteLine ("File not Write ");
- Return;
- }
- Swt. WriteLine ("chenhailong ");
- Swt. Close ();
- }
In C language ^ how to use a1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010
B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011
^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.
//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].
C Language & |! What is the? & operator used to extract the address of a variable.
For example, if you define a variable, the system will allocate a space in the memory during compilation.
The location of the space in the memory is its address. & Extract its address.
E. g int a; assign an address to it during compilation, for example, 2000; & a is 2000.
If an integer pointer Variable p, p = & a; is defined, the address 2000 of a is assigned to p. P = 2000 after running.
Another example is scanf ("% d", & a). When you enter 3, it first knows the address of a according to & a, and finds the space of a in the memory by the address, write 3 to this space.
* Is a pointer operator, which is opposite to &. It extracts the value of a Variable Based on the address of the variable.
For example, * the value of a is 3 of variable.
The following is a summary of the pointer used in the definition and description.
Int * p; defines a pointer to integer data.
Int * p [n]; defines the pointer array p, which consists of n pointer elements pointing to integer data.
Int (* p) [n]; p is the pointer variable pointing to a one-dimensional array containing n elements.
Int * p (); p is the function that returns a pointer pointing to integer data.
Int (* p) (); p is the pointer to the function. This function returns an integer value.
Int ** p; p is a pointer variable that points to an integer Data Pointer variable.
If you want to learn more about the system, you can refer to tan haoqiang's c Programming (the third edition), which is easy to understand. Is a good C language learning material.