Csaba Gabor
> On 5 Sep 2005 14:27:03 -0700, "Csaba Gabor" wanted:
>
> FTYPE PHPFile=IF DEFINED APPDATA (c:\php.net\php.exe "%1" %*) else
> (c:\php.net\php-win.exe "%1" %*)
For those arriving late to the program, in today's exciting episode
everyone is wondering whether there is a way to have php.exe run when
test.php is typed at the command prompt Vs. having php-win.exe run when
it is double clicked from Explorer. This is because php-win.exe
suppresses the ugly command window when it runs, but only php.exe will
send its output to the command window (thus enabling useful things like
debugging).
Earlier we saw that
ASSOC .php=PHPFile
FTYPE phpfile="CScript.exe" c:\php-net\dispatchPHP.vbs "%1" %*
tied extensions to actions so that when either test.php was typed or
doubleclicked, the file (along with any arguments from the command
line) would be passed to dispatchPHP.vbs Let's tune in to see how it's
going......
Here's what I wrote for dispatchPHP.vbs:
Set oSH = CreateObject("WScript.Shell")
runPrefix = "c:\php.net\php.exe "
runLine = ""
Set oArg = WScript.Arguments
For i=0 to oArg.count-1 'Reassemble all the arguments
runLine = runLine & """" & oArg(i) & """ "
Next
'Next line detects if we are in a command window
cmdP = (oSH.Environment("Process").Item("=ExitCode")<>"")
If cmdP Then 'In a command window
oSH.Exec runPrefix & runLine
Else 'Else (Explorer)
runPrefix = "c:\php.net\php-win.exe "
oSH.Run runPrefix & runLine, 0, false
End If
Hurrah, hurrah, it works! But there is one problem which I would love
a solution for. Because FTYPE specified CScript, it means that when
invoked from Explorer, there will be a momentary flash from the CScript
command window while it dispatches PHP. Well, that is better than it
staying around for the whole process, but can't we do better by telling
FTYPE WScript instead of CScript? In fact, that will clean up the
flashy thingy on the screen, but now I cannot get output to the command
window when I invoke test.php from the command window. And that is
what today's episode is all about.
So let's assume that the FTYPE now has WScript instead of CScript.
How can I get WScript to get output to the command window?
I tried:
1. reentering via CScript and then WScript.StdOut.Write modeled on:
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/54d3df2e29211bad/
2. Set fs=CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("CON:",True)
a.Write "Something"
modeled on:
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/70a2ff21a70c5ca9/
3. An "unsupported" Tom Lavedas idea:
dim sout, oFS
const StdOut = 1
set oFS = CreateObject("Scripting.FileSystemObject")
set sout = oFS.GetStandardStream(StdOut)
sout.Write "Hello World"
described at:
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/eead9d107d85041c/
all to no avail.
1 doesn't complain - you just don't get anything.
2 dies with Permission denied.
3 dies with handle is invalid on the sout.Write line.
Can anyone improve my scenario?
Frankly, I think the best idea (though I have not got it work) would be
along the lines of modifying FTYPE to be something like:
FTYPE PHPFile=IF DEFINED PROMPT ("c:\php.net\php.exe" "%1" %*) ELSE
("c:\php.net\php-win.exe" "%1" %*)
possibly completely enclosed in quotes. But my attempts have so far
failed in permission denied or being asked by Windows what program to
use to run the file.
Csaba Gabor from Vienna
Oh, (note the last line should print to the command window) test.php
is:
$oWS = new COM("WScript.Shell");
$out = implode("\n", $GLOBALS['argv']);
$oWS->popup ($out, 4, "PHP Popup", 131120);
var_dump ($GLOBALS['argv']);
?>
>
> FTYPE PHPFile=IF DEFINED APPDATA (c:\php.net\php.exe "%1" %*) else
> (c:\php.net\php-win.exe "%1" %*)
For those arriving late to the program, in today's exciting episode
everyone is wondering whether there is a way to have php.exe run when
test.php is typed at the command prompt Vs. having php-win.exe run when
it is double clicked from Explorer. This is because php-win.exe
suppresses the ugly command window when it runs, but only php.exe will
send its output to the command window (thus enabling useful things like
debugging).
Earlier we saw that
ASSOC .php=PHPFile
FTYPE phpfile="CScript.exe" c:\php-net\dispatchPHP.vbs "%1" %*
tied extensions to actions so that when either test.php was typed or
doubleclicked, the file (along with any arguments from the command
line) would be passed to dispatchPHP.vbs Let's tune in to see how it's
going......
Here's what I wrote for dispatchPHP.vbs:
Set oSH = CreateObject("WScript.Shell")
runPrefix = "c:\php.net\php.exe "
runLine = ""
Set oArg = WScript.Arguments
For i=0 to oArg.count-1 'Reassemble all the arguments
runLine = runLine & """" & oArg(i) & """ "
Next
'Next line detects if we are in a command window
cmdP = (oSH.Environment("Process").Item("=ExitCode")<>"")
If cmdP Then 'In a command window
oSH.Exec runPrefix & runLine
Else 'Else (Explorer)
runPrefix = "c:\php.net\php-win.exe "
oSH.Run runPrefix & runLine, 0, false
End If
Hurrah, hurrah, it works! But there is one problem which I would love
a solution for. Because FTYPE specified CScript, it means that when
invoked from Explorer, there will be a momentary flash from the CScript
command window while it dispatches PHP. Well, that is better than it
staying around for the whole process, but can't we do better by telling
FTYPE WScript instead of CScript? In fact, that will clean up the
flashy thingy on the screen, but now I cannot get output to the command
window when I invoke test.php from the command window. And that is
what today's episode is all about.
So let's assume that the FTYPE now has WScript instead of CScript.
How can I get WScript to get output to the command window?
I tried:
1. reentering via CScript and then WScript.StdOut.Write modeled on:
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/54d3df2e29211bad/
2. Set fs=CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("CON:",True)
a.Write "Something"
modeled on:
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/70a2ff21a70c5ca9/
3. An "unsupported" Tom Lavedas idea:
dim sout, oFS
const StdOut = 1
set oFS = CreateObject("Scripting.FileSystemObject")
set sout = oFS.GetStandardStream(StdOut)
sout.Write "Hello World"
described at:
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/eead9d107d85041c/
all to no avail.
1 doesn't complain - you just don't get anything.
2 dies with Permission denied.
3 dies with handle is invalid on the sout.Write line.
Can anyone improve my scenario?
Frankly, I think the best idea (though I have not got it work) would be
along the lines of modifying FTYPE to be something like:
FTYPE PHPFile=IF DEFINED PROMPT ("c:\php.net\php.exe" "%1" %*) ELSE
("c:\php.net\php-win.exe" "%1" %*)
possibly completely enclosed in quotes. But my attempts have so far
failed in permission denied or being asked by Windows what program to
use to run the file.
Csaba Gabor from Vienna
Oh, (note the last line should print to the command window) test.php
is:
$oWS = new COM("WScript.Shell");
$out = implode("\n", $GLOBALS['argv']);
$oWS->popup ($out, 4, "PHP Popup", 131120);
var_dump ($GLOBALS['argv']);
?>