HP3000-L Archives

July 2007, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"John K." <[log in to unmask]>
Reply To:
John K.
Date:
Mon, 9 Jul 2007 21:04:14 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (232 lines)
Hi Roy and Olav,

Sorry for the delay in responding!  I left for a photo shoot at the 
beach Thursday morning, was swamped when I got home and checked email 
Saturday, and then the server hosting three of my domains failed, so 
it has been busy and then rough few days.  (yeah, the photographing a 
beautiful model on the beach part wasn't so bad ;-)

Actually, what I was trying to do was come up with a way of, under 
the Windows XP Pro command line, doing what is so easy to do under 
MPE in a batch job.

I guess an over-simplification would be to say that I wanted to do 
the equivalent of the following in a Windows .bat file, but it can't be done:

!job jobname,username/pass.acctname/pass
!run php.php;info="phpscriptname"
first_line_of_data_for_php_script
second_line_of_data_for_php_script
...
last_line_of_data_for_php_script
!run php.php;info="phpscriptname"
first_line_of_data_for_php_script
second_line_of_data_for_php_script
...
last_line_of_data_for_php_script
!run php.php;info="phpscriptname"
... etc.
!eoj

I received some private replys that basically said "not possible with 
the Windows command line interpreter."

Thus, I wrote a little PHP script that reads a "batch file" of my own 
format, which looks sort of like:

!php php_script_name
first_line_of_data_for_php_script
second_line_of_data_for_php_script
...
last_line_of_data_for_php_script
!php php_script_name
first_line_of_data_for_php_script
second_line_of_data_for_php_script
...
last_line_of_data_for_php_script
!php php_script_name
first_line_of_data_for_php_script
second_line_of_data_for_php_script
...
last_line_of_data_for_php_script
!eoj

Look familiar? (LOL)

It works by always reading at least one line ahead of where it is 
executing.  If the line following the "!php" line does NOT start with 
"!" then it creates a temp file, copies the line it just read and all 
line which follow up to the next line that starts with a "!" into the 
temp file.  When it sees a line that starts with a "!" it closes the 
temp file, then creates a command string for the Windows CLI that 
specifies the just-created temp file as the Stdin, and has the system 
statement execute the command.  When the system statement completes, 
it looks in the buffer to see if the line in the buffer (which 
started with "!" is a valid command (of which "php" and "eoj" are the 
only two valid commands at present).  If the command is other "eoj" 
then it terminate, otherwise the process repeats.

Anyway, that was my solution.  And one of the reasons I like PHP - it 
runs on almost every platform.  Now all PHP needs is access to Tk on 
Windows (like Perl has)!

Thanks All!

John

At 2007-07-05 03:12 PM, Roy Brown wrote:
>In message 
><[log in to unmask]>, 
>  John K. <[log in to unmask]> writes
>>It has been quite a while since I've had to do a lot with the 
>>Windows command line, and now I find I can't remember certain 
>>things, such as...
>>
>>I need to create a .bat file that contains a command to invoke a 
>>php script multiple times, with the "stdin" for each invocation of 
>>the php script immediately following the command invoking the 
>>script (ah, how easy it was to do such things in MPE).  Below is an 
>>example of what the .bat file structure would be:
>>
>>c:\php\php.exe [php_script_name] [?_something_to_tell_DOS_stdin_data_follows]
>>[line_0_of_data]
>>[line_1_of_data]
>>[line_2_of_data]
>>...
>>[line_n_of_data]
>>[eod_mark-though_it_was_ctrl_z]
>>c:\php\php.exe [php_script_name] [?_something_to_tell_DOS_stdin_data_follows]
>>[line_0_of_data]
>>[line_1_of_data]
>>[line_2_of_data]
>>...
>>[line_n_of_data]
>>[eod_mark-though_it_was_ctrl_z]
>>c:\php\php.exe [php_script_name] [?_something_to_tell_DOS_stdin_data_follows]
>>[line_0_of_data]
>>[line_1_of_data]
>>[line_2_of_data]
>>...
>>[line_n_of_data]
>>[eod_mark-though_it_was_ctrl_z]
>>
>>etc. - you get the point.
>>I tried using "<" for the 
>>"[?_something_to_tell_DOS_stdin_data_follows]" but that didn't 
>>work.  I can get it to work if the data is in an external file, but 
>>that won't work for this application.  I thought CTRL-Z was the 
>>"end of data" but that just seems to cause the command window to hang.
>>
>>I guess I'm Googling the wrong keywords as I'm not finding what I'm 
>>looking for.
>>
>>Any suggestions or assistance are greatly appreciated!
>>
>>John (running late to pick up my children for a movie!)
>>
>>*** When replying to this message, please do not delete these ***
>>*** signature lines. Otakon Katsucon HP3000-L @classiccmp.org ***
>>*** DigitalCosplay.com    JohnKorbPhoto.com     JohnPKorb.com ***
>
>Hi John
>
>I don't know if you got any replies privately.
>
>But if not, I can at least share my ignorance with you, given that I 
>know nothing of php; and also possibly not enough of how MPE works 
>in this area :-)
>
>If I don't miss my guess on MPE, then if php.exe was an MPE program 
>running in a jobstream, it wouldn't be MPE passing the subsequent 
>lines to php exactly.
>
>Rather, they would only be passed to php if it specifically 
>requested them, line by line; though then, as the default feed for 
>the request would be from STDIN, and the datastream itself would be 
>STDIN, MPE would then pass the lines in one by one.
>
>I hope this does not sound like splitting hairs... but it has two 
>implications.
>
>The first is that only as many lines would be passed in as php.exe 
>(via its script) requested. So if php.exe requested less lines than 
>there were of data, and then quit, MPE would try to execute any 
>remaining lines of data as commands.
>
>And conversely, if php.exe requested more lines, then the later php 
>command lines themselves would be passed in.
>
>So, to make the above work on MPE. with a possibly variable number 
>of lines to be fed into each php invocation, you'd have to have a 
>loop in your php code, and some sort of closing token ( for which 
>CTRL-Z might be fine) that told the php code to stop executing and to quit.
>
>I don't think it's going to be much different from this under DOS 
>for you. And I don't think you can pipe multiple lines into a DOS 
>command in quite the way you seem to want to above.
>
>I see two choices: firstly, can you build the file you need on the 
>fly? You say an external file won't work, but not exactly why).
>
>Taking one invocation of PHP, above:
>
>c:\php\php.exe [php_script_name] [?_something_to_tell_DOS_stdin_data_follows]
>[line_0_of_data]
>[line_1_of_data]
>[line_2_of_data]
>...
>[line_n_of_data]
>[eod_mark-though_it_was_ctrl_z]
>
>can you invert and extend this, thus:
>
>[line_0_of_data] > tempfile
>[line_1_of_data] >> tempfile
>[line_2_of_data] >> tempfile
>...                    >> tempfile
>[line_n_of_data] >> tempfile
>
>c:\php\php.exe [php_script_name] < tempfile
>
>and you may or may not need:
>
>[eod_mark (some convention, perhaps ctrl_z] >> tempfile
>
>depending on whether you need something to tell the invocation of 
>php to quit or not - if it's a variable number of line, you probably 
>will, though).
>
>This can all still be done on the fly, but requires the php 
>invocation to follow, not precede, the data, and for the >(>) 
>tempfile to be appended to each data line.
>
>
>The second possible option, which would allow you to keep the format 
>in which, is to explicitly tell php to read the STDIN; it can do 
>this, but needs to be told to, apparently:
>
>http://uk2.php.net/manual/en/features.commandline.php
>
>where it describes:
>
>If you want to read a single line from stdin, you can use
><?php
>$line = trim(fgets(STDIN)); // reads one line from STDIN
>fscanf(STDIN, "%d\n", $number); // reads number from STDIN
>?>
>
>I hope this helps. As I said above, I would not be my own first 
>choice of php expertise :-)
>--
>Roy Brown        'Have nothing in your houses that you do not know to be
>Kelmscott Ltd     useful, or believe to be beautiful'  William Morris


John
*** When replying to this message, please do not delete these ***
*** signature lines. Otakon Katsucon HP3000-L @classiccmp.org ***
*** DigitalCosplay.com    JohnKorbPhoto.com     JohnPKorb.com ***

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2