Home > Software engineering >  VB enter CMD command
VB enter CMD command

Time:10-02

The last post is an input information, zhao four teacher gave a train of thought, create bat file content is: the su015 & lt; In. TXT & gt; Out. TXT
Code to the
 Private Sub Command1_Click () 
Dim STR As String
On the Error Resume Next

Open "c: \ Tribon \ M3 \ Bin \ in TXT" For the Output As the # 1
Print # 1, "e: \ 1. TXT"
Close # 1

Open "c: \ Tribon \ M3 \ Bin \ TMP bat" For the Output As the # 1
Print # 1, CD/d "c: \ Tribon \ M3 \ Bin"
Print # 1, "su015 & lt; In. TXT & gt; Out. TXT "
Close # 1

The Shell "c: \ Tribon \ M3 \ Bin \ TMP bat", vbHide

Open "c: \ Tribon \ M3 \ Bin \ out TXT" For Input As # 1
The Line Input # 1, STR

The Debug. Print STR
Close # 1

Kill "c: \ Tribon \ M3 \ Bin \ in TXT"
Kill "c: \ Tribon \ M3 \ Bin \ TMP bat"
Kill "c: \ Tribon \ M3 \ Bin \ out TXT"
End Sub

But this time to enter two input information, the following figure



I use su016 & lt; In the. TXT & lt; In2. TXT but doesn't work, consult everybody how to deal with, thank you!

CodePudding user response:

Wrote two lines in the. TXT!
 e: \ 111. TXT 
Da. TXT

CodePudding user response:

The building Lord not extrapolate?
 Private Sub Command1_Click () 
Dim STR As String
On the Error Resume Next

Open "c: \ Tribon \ M3 \ Bin \ in TXT" For the Output As the # 1
Print # 1, "e: \ 111. TXT"
Print # 1, "da. TXT"
Close # 1

Open "c: \ Tribon \ M3 \ Bin \ TMP bat" For the Output As the # 1
Print # 1, CD/d "c: \ Tribon \ M3 \ Bin"
Print # 1, "su016 & lt; In. TXT & gt; Out. TXT "
Close # 1

The Shell "c: \ Tribon \ M3 \ Bin \ TMP bat", vbHide

Open "c: \ Tribon \ M3 \ Bin \ out TXT" For Input As # 1
The Line Input # 1, STR

The Debug. Print STR
Close # 1

Kill "c: \ Tribon \ M3 \ Bin \ in TXT"
Kill "c: \ Tribon \ M3 \ Bin \ TMP bat"
Kill "c: \ Tribon \ M3 \ Bin \ out TXT"
End Sub

CodePudding user response:

 using the command redirection operator can use the redirection operator will command input and output data stream from the default location of reset 
To the different position, the position of the input or output data stream is the handle,

The following table lists the available handle,

Handle to handle digital code description
Keyboard input STDIN 0
STDOUT 1 output to the command prompt window
STDERR 2 error output to the command prompt window
UNDEFINED 3-9 these handles separately defined by the application, and is the specific tools,

Numbers 0 to 9 on behalf of the 10 top handle, you can use the command Cmd. Exe to run the program and the program before 10
Handle any of the redirection, to want to use the specified handle, but in front of the redirection operators enter the handle
Numbers, if you do not define handle, then the default & lt; Redirect input operator is 0, the default & gt; Redirecting output
Operator is 1, type & gt; Or & lt; Operator, must specify the location of the to read or write data, you can specify
File name or another handle to existing,

To specify a redirect to the existing handle, please use and (& amp;) Characters, followed by number to handle to redirect
(e.g., & amp; Handle #), for example, the following command can handle 2 (STDERR) is redirected to the
Handle 1 (STDOUT) :

2> & 1

The following table lists the can be used to redirect the input and output data flow operator,

Redirection operator description
Will command output is written to the file or device (such as printers), instead of writing in the command prompt window or handle,
> Add the command output to the end of the file and not delete the information in the file,
& To write the output of a a handle to another handle input,
<& From a handle read input and write it to another handle output,
| reads the output from one command and writes it to the input of another command, also known as pipes,

By default, available from the keyboard input commands to handle (STDIN) sent to the Cmd. Exe, and then by the
Cmd. Exe command output (i.e., handle to STDOUT) sent to the command prompt window,

Redirect input (& lt;)
Keyboard input to redirect to a file or device, please use & lt; Operator, for example, from the File. TXT for
The sort command input, please type:

Sort
The contents of the File. TXT will by alphabetical list displayed in the command prompt window,

fileInformation, for example, if the & lt; & 2 start the program, then all attempts to handle to read zero operation will fail, because other
Handle 2 original is only write access to open,

Note that

0 is & lt; Handle to the default redirect input operator,
Redirecting output (& gt;)
Almost all of the command will be output to a command prompt window, even if sends output to drive or printer
Command will be at the command prompt window displays a message and prompts,

Output from the command prompt window to redirect to a file or device, please use & gt; Operator, can be in a lot of command
Use this operator, for example, will dir output redirection to Dirlist. TXT, type:

Dir> Dirlist. TXT

If Dirlist. TXT does not exist, Cmd. Exe will create the file, if Dirlist. TXT, Cmd. Exe
Will use the dir command output to replace the information in the file,

You want to run the netsh routing dump command, and then sends output to the Route. The CFG, type:

Netsh routing dump> C: \ route. The CFG

Operator can open with only write access to the attribute of the specified file, so can't read the file using the operator,
For example, if use redirect & gt; & 0 start the program, then all attempts to write handle 1 operation will fail, because
Handle zero initially was opened read-only access,

Note that

1 is & gt; Redirecting output operators handle to the default,
Copy the handle
Redirection operator & amp; Can be output or input from a specified handle to another handle to specify, for example,
Dir to output to a File. TXT and the error output to a File. TXT, type:

Dir> C: \ file. TXT 2 & gt; & 1

Copy the handle, you can copy the handle all the characteristics of the original state, for example, if a handle has write access only
Attribute, the handle of all copies have write access to attributes only, cannot be a handle with read-only access attribute
To another with only write access attributes of handle,

Use & amp; Operator to redirect input and copy
Would like to redirect input operator (& lt;) And copy operator (& amp;) Used together, the specified file must already exist,
If the input file exists, Cmd. Exe will open the file in a read-only way, then the files contained in the character as a
Input is sent to the command (like input from the keyboard), if the specified handle, handle to Cmd. Exe will specify
Copying to handle to the existing system,

To handle zero input, for example, read (STDIN) way to open the File. TXT, type:


To open the File. TXT, and in the content after sorting the output (STDOUT) sent to the command prompt window, type:

Sort
To find the File. TXT, then 1 (STDOUT) and handle handle 2 (STDERR) is redirected to the
Search the. TXT, type:

Findfile file. Txt> Search. TXT 2 & lt; & 1

To handle input reads 0 (STDIN) way to copy the user to define handle 3, type:

<& 3

Use & amp; Redirect the output and copy
If redirect the output to a file, and specifies the existing filename, Cmd. Exe to write only way to open the file and reply
Cover the file content, if the specified handle, Cmd. Exe file is copied to the existing handle,

To user defined 3 copied to handle handle 1, please type:

& 3

To handle will include 2 (STDERR) of all output from the ipconfig command is redirected to the
Handle 1 (STDOUT), and then redirect the Output to the Output. The log, please type:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related