Jump to content

stdoutread's behaving badly?


jefhal
 Share

Recommended Posts

Is it okay to use more than one run/stdoutread in one script? I tried two and they seem to be colliding into each other. If one works, the other fails, and vice-versa. I've now reverted my code back to using another method, but wondered what was happening.

Since you have to use "Run" rather than "Runwait" could it be that the second one is starting before the first one is finished? For example, I used one run(@comspec...ipconfig) and one run(@comspec...ping) and one run(@comspec...dosxpres). They all use $PID, $Cmdout, and $STDOUT_CHILD as the variable names. Do I have to re-initialize these for each "run" statement I do?

Also, if I name the child process id: $PID, will I ever see that process id number in my process id list in the task manager? I see the parent process, e.g. "ping" or "dosxpres", but never the child process. Is it just too fast to see?

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Link to comment
Share on other sites

Global $total_01, $total_02

$pid_01 = Run(@ComSpec & ' /c dir ' & @SystemDir & ' /s/b', '', @SW_HIDE, 2)
$pid_02 = Run(@ComSpec & ' /c dir "' & @ProgramFilesDir & '" /s/b', '', @SW_HIDE, 2)

While True
    $line_01 = StdoutRead($pid_01, True)
    $process01 = @error
    If Not @error Then $total_01 &= $line_01
    $line_02 = StdoutRead($pid_02, True)
    $process02 = @error
    If Not @error Then $total_02 &= $line_02
    If $process01 And $process02 Then ExitLoop
WEnd

FileWrite(@HomeDrive & '\test_01.txt', $total_01)
FileWrite(@HomeDrive & '\test_02.txt', $total_02)

Tests show running 2 at once works OK.

This is my understanding to your questions:

if the 1st one does finish before the 2nd, then the 1st has little or no stdout. If the Run Stdout processes are running at the same time, then different variables would be needed. If the processes run at different times, then the same variables would just be reassigned the new values given to them, except for $STDOUT_CHILD, which is a constant setting.

Windows sets the ProcessID, so it should show in TaskManager. Child process? Unknown to myself of what process.

Link to comment
Share on other sites

This is my understanding to your questions:

1. If the 1st one does finish before the 2nd, then the 1st has little or no stdout.

2. Windows sets the ProcessID, so it should show in TaskManager. Child process?

MHz, thanks for your proof of concept! That helped restore my level of confidence greatly. Part of my problem was that I was not properly removing crlf's at the end of some of my parsing results. That led to crlf's going into variables, which led to lost data on the output side. That's because the field into which the data was being sent only allows one line of input. (Active Directory Computer "description" field)

However, given what you said in 1. I may still be losing data in the first stdout if that finishes too late? I'll have to test again at work on Monday. (No AD at home...)

As to item 2. the child process I refer to is the one mentioned in the help file: "The process ID of a child process, as returned by a previous call to Run." For example, lets say I run ipconfig and put the process ID into $PID. That number should match the process id that I see in the Task Manager. However, I can never match up $PID with any PID in the Task Manager. Is that because the process that I'm looking for has aleady closed? Shouldn't I see the PID briefly in TM?

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Link to comment
Share on other sites

However, given what you said in 1. I may still be losing data in the first stdout if that finishes too late? I'll have to test again at work on Monday. (No AD at home...)

@jefhal, I'd use two While loops: one to read the ipconfig output until you get @error = -1, then extract your results, then call ping, etc.

You should always read as much as you can from earlier processes before you carry on to subsequent ones. Reasons for this are both because there may be a delay in in an earlier process starting up and also because the first output written may be a tiny useless blurt of just a few characters. StdoutRead only waits for something to get written and returns that, it doesn't care how little. While you can specify the number of characters that you want read it's only used to limit the max chars read, it won't make StdoutRead wait for that many...

[Edit: Spelling]

Edited by DaveF

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...