I'm going to be passed a dos based command to my vb6 program. I would like to take the multiline output of that command and create a command line command for each line it generates. The only way I know to do this at the moment is to pipe it to a text file and then read that file in a line at a time creating the command and issuing it or creating a batch file and executing it. Either way, the extra I/O will probably cause overhead I don't want. Any ideas?

Dani AI

Generated

This thread is about taking a console program's multiline output in a VB6 host and turning each output line into a new command without touching disk. wants to avoid the extra I/O; pointed toward using a pipe. Below are practical, low-risk ways to do that in VB6 and what to watch out for.

The simplest approach that avoids temp files is to run the command through Windows Script Host and read its StdOut stream (WshShell.Exec). That gives a line-at-a-time text stream so each received line can be transformed into the next command and dispatched immediately. For more control (redirecting both stdout and stderr, nonblocking reads, finer process handles) use the Win32 pattern with CreatePipe/CreateProcess and read the child process handles directly — this is more work but scales better for high-volume output.

Important implementation notes:

  • Stream and process each line as it arrives. Do not accumulate the entire output in memory for large outputs.
  • Drain both stdout and stderr or the child process can deadlock when pipe buffers fill.
  • If you will spawn a process for every input line, throttle or queue the work; otherwise the system can be overwhelmed by many simultaneous child processes.
  • Normalize and escape/quote each line before building the command so spaces and special characters do not break cmd parsing.
  • Keep the UI responsive by performing the read/processing on a worker (or use DoEvents carefully).

For concrete reference on techniques and pitfalls when redirecting child-process I/O, see Creating a Child Process with Redirected Input and Output. For the easy, script-style method usable from VB6, see the WshShell Exec documentation: .

Recommended Answers

All 3 Replies

I'm going to be passed a dos based command to my vb6 program. I would like to take the multiline output of that command and create a command line command for each line it generates. The only way I know to do this at the moment is to pipe it to a text file and then read that file in a line at a time creating the command and issuing it or creating a batch file and executing it. Either way, the extra I/O will probably cause overhead I don't want. Any ideas?

Why to create a text file? Your pipe itself saves this purpose. FIFO.

Why to create a text file? Your pipe itself saves this purpose. FIFO.

I need to alter the output so that it becomes the executable I need. Can I pipe to an array?

I need to alter the output so that it becomes the executable I need. Can I pipe to an array?

That depends upon the size of your output. If it is samll you can size and resize an array. But if it is too large your program address space will demand more memory which may cause other programs not to co-exist.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.