Interactive input

  • Thread starter Thread starter Csaba
  • Start date Start date
C

Csaba

Hi, I'm at a bit of a loss here - I'd like to activate a program which
demands keyboard input and then provide a single line of input, which
will terminate the program. I'll provide the specifics in the next
paragraphs, and then the motivation.

I'm running a VBScript program (this is actually via an
MSScriptControl.ScriptControl COM object) and I want to execute a Run
command:
Dim oWSH
Set oWSH = CreateObject("WScript.Shell")
oWSH.Run "cmd /C php-cgi -a ...", 0, true

Now, this Run command wants to invoke php-cgi.exe to run a short
script. However, the only way that php-cgi.exe accepts a non file
script is by going into interactive mode. So, ... from the keyboard, I
would do:
php-cgi -a
<?php $o=new COM('WScript.Shell');$o->popup('Working');exit(); ?>

Of course, that second line is typed interactively and received by
php-cgi.exe, not the command interpreter. And the final exit causes
php-cgi to terminate. My question is:

Is there a way that I can specify to CMD (within the oWSH.Run command)
that it should send that second line to STDIN?

Thanks,
Csaba Gabor from Vienna


For the curious, the real problem I'm trying to solve is that I want to
be able to display (upon an instance of IE invoked with $ie=new
COM("InternetExplorer.Application")) the phpinfo() that the CLI
(command line interpreter) versions of PHP return. These CLI versions
are php.exe and php-win.exe. What happens, however, is that the CLI
versions only return a text version of phpinfo() and not an HTML
version, so I should have to format it myself. However, there's a lot
of style sheet information within this HTML formatting and I would
rather get this in an automated way.

My idea for how to do this is to invoke php-cgi.exe (which DOES provide
the type of formatting I want) and strip the <style>...</style> portion
of the output. And I can do this via the process described at
http://php.net/proc_open . Unfortunately, invoking proc_open results
in a nasty command prompt flash. Now, this ugly flash is avoided if I
take a similar approach using a ScriptControl COM object, which is how
I got to the question above. Of course I will have slightly longer
code to supply top php-cgi, but the code above illustrates the idea.
 
Hi, I'm at a bit of a loss here - I'd like to activate a program which
demands keyboard input and then provide a single line of input, which
will terminate the program. I'll provide the specifics in the next
paragraphs, and then the motivation.

I'm running a VBScript program
....snip

Instead of using the Run method to execute the program,
use the WshScriptExec object to start an instance of it, and
run the VBS script with CSCRIPT from the command line.
Then you'll have access to both the STDIN and STDOUT
streams of your program; your VBS script will be able to act
as the program's "user", supply input, and read any output, too.

See the WSH help files under WshScriptExec object and
the links to STDIN and STDOUT for syntax examples.
 
William said:
...snip

Instead of using the Run method to execute the program,
use the WshScriptExec object to start an instance of it, and
run the VBS script with CSCRIPT from the command line.
Then you'll have access to both the STDIN and STDOUT
streams of your program; your VBS script will be able to act
as the program's "user", supply input, and read any output, too.

Hi William, thanks for your response.
There are two things that I am trying to avoid in getting to my goal:
one is the use of temporary files and the other is the display of any
unnecessary cmd/command/DOS boxes (and for these purposes, any display
is unnecessary).

I agree that your method (.Exec) would allow me the necessary IO to
php-cgi.exe that I needed. And that could be wrapped in a .Run to make
it hidden. Unfortunately, CScript.exe/WScript.exe to my knowledge
require a file name to be passed to them. They don't have a way of
accepting a script from the command line (this is analagous the problem
with php-cgi.exe).

Csaba Gabor from Vienna
 
Back
Top