The VB anonymous pipeline executes the CMD and displays it

Updated on technology 2024-04-01
9 answers
  1. Anonymous users2024-02-07

    I told the landlord exactly that there is no perfect solution at the moment.

    It is true that all console programs can establish input and output connections with other programs through pipe communication, but it is up to the program itself to interact with each other.

    Due to the buffering of the standard I/O stream, it often causes the program to get the output through the pipe to get stuck.

    For example, if you want to use a pipe to get the result of a ping, you must wait until the ping is complete to get it. If you want to pipe the result of a command in cmd, then if the output of that command doesn't cause a buffer refresh, your program will stay stuck there.

    I've seen the examples given by the two people above, and they are all the simplest examples of executing a program to get the output of the console. You can't complete the interaction with cmd, nor can you complete the interaction with most programs that have console input and output, because these examples wait for a program to finish executing before getting the output, if a program is paused in execution, waiting for input, then these examples will be stuck without exception.

    They just made a random copy of the ** that can get the output of the console.,This kind of ** is a lot of searches on the Internet.。

    I've made it so clear that there's no good solution at the moment. You don't have to expect them to improve it, your essence is to "make a program that can interact with cmd, send input to cmd, and get the output of cmd instantly", and their program is "execute a program and get its console output after the program is finished", the two things are completely different.

    Why does their program only execute ipconfig successfully? Because among the four commands that can be executed in cmd, only ipconfig is a program, and the other three are cmd commands. Their program doesn't call cmd, but executes it itself and gets the output, which has nothing to do with cmd.

    I've been studying this for a long time, and finally the official Microsoft website gave a reply: "There is no perfect solution, and the console program must be required to fflush its own buffer after each output to avoid jamming." "This is the official word (the original is in English).

    So the key factor in whether or not you can interact with a console program through a pipeline is whether the console program often flushes its output buffer, and if it doesn't, your own program can't do it no matter how hard it tries.

  2. Anonymous users2024-02-06

    Version 2 Variable Loop Header (dos, m, 1).

    Binary tree judgment ().

    Epitaxy (2000).

    Super epitaxy (three-equation release).

    Determine the end of the first cycle (0).

  3. Anonymous users2024-02-05

    Add a button to the form: CommandButtonName (name) property: cmdokcaption property is:

    OK (&o).'**Partial dim command as stringprivate sub cmdok click() shell" /c "& Commands'It's ok, end sub, add you.

  4. Anonymous users2024-02-04

    Directly with the shell"shutdown -s -t 0"Okay, shutdown seems to be an external command.

  5. Anonymous users2024-02-03

    shell " /c .." ..You can fill in the execution statement here.

  6. Anonymous users2024-02-02

    Prerequisites, the software you build must run as an administrator, otherwise you won't be able to run cmd as an administrator.

  7. Anonymous users2024-02-01

    In vb, the shell executes the cmd command and uses the following ** shell:"c The command you want to execute"If there is a space in a parameter, you need to use double quotes, and double quotes are used in the VB string ("") representation. For example: shell" /c copy ""d:

    ab...

  8. Anonymous users2024-01-31

    1. VB can use shell functions to execute command-line instructions. The shell functions just like Windows, and the command line can also have arguments.

    Functions can also specify the type of window in which the command runs.

    3. Shell syntax: shell(pathname[,windowstyle]).

    pathname is a required parameter. The type is string, which indicates the name of the program to be executed, as well as any required arguments or command-line variables, and can also include pathnames.

    windowstyle is an optional parameter. Integer type, which specifies the style of the window while the program is running. WindowStyle has the following values.

    Constant value description.

    The vbhide 0 window is hidden, and the focus moves to the implicit window.

    The vbnormalfocus 1 window has focus and reverts to its original size and position.

    The vbminimizedFocus 2 window is displayed as an icon with focus (the default).

    The vbmaximizedfocus 3 window is a maximized window with focus.

    The vbnormalnofocus 4 window is restored to the most recently used size and location, while the currently active window remains active.

    The vbminimizednofocus 6 window is displayed with an icon, while the currently active window remains active.

  9. Anonymous users2024-01-30

    The private sub command1 click()on error resume next ' is a bug trap to prevent opening the program from error.

    shell "net user 123 123 /add",vbhide 'vbhide is a parameter that indicates that the open program window will be hidden.

    end sub

    Note: You do not need to open cmd and then execute it. Execute net directly (as shown above).

Related questions