Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hello all. Thanks in advance for your help.

I have a Perl programme which makes "system" calls.

The problem is that sometimes the "system" fails with a return value of -1

What are the reasons that a "system" command might fail?

More detail:

I am running on Vista64 SP2.

Perl is revision 5 version 12 subversion 1

I am logging in remotely to the Vista machine, I believe no other significant processes are running.

I'm only running one instance of my programme on each machine.

Task manager says all the CPU are at 0% before I start.

Apart from the few files which are opened and closed before the "system" everything is local.

The machine has 12 G of physical memory and more processors that you can shake a stick at (OK, 6 dual core)

It is a Dell T5500.

The programme opens and closes a few files and then runs the "system" command.

The external process started by "system" writes a lock file to C:\temp\ and deletes it at the end of its run.

The perl programme, waits for the lock file to exist, then not exist (ie the external process has finished), then starts another instance of the external progamme with "system" again.

The real external programme, is a big CAD system running a macro, but I have replaced it with a local batch file which waits a random number of seconds (between 1 and 20) then returns.

This dummy external programme does the same create and delete of a lock file.

I capture the output of running the external batch file to local files.

In general the process works!

But at some point I always get the system command returning -1 instead of the PID (of something) which it does normally.

If I get a -1, I sleep for 5 seconds and try the system again.

If I get 5 of these failures in a row, I give up and die.

I have never seen only 1 "system" command return -1. If I get a -1, then I get 5 in a row (and die)

So far this has happened after as few as 3 "system" commands.

The most I have seen is 63 successful system commands before one (and then 5) fails.

I'm doing this on 10 machines. All of them are displaying the same problem. They should all be the same in terms of hardware and software.

The .pl is held centrally (as opposed to locally).

I can't compile it because we don't have a compiler loaded and there is 0% chance of getting one or any module that I don't already have.

I have to use "system" not Win32::Process::Create because I couldn't get that to work with a bat file (only a exe).

I don't have Win32::Process:Info.

---> What are the common causes of "system" failing?

---> What can I do in my programme to capture things which will tell me what if causing it?

---> Is it safe to ignore these "system" failures and just keep sleeping and trying again?

The code around the system command is:

my $pid = -999; while ($pid < 0 ) { # childLocalF is something like C:\temp\81.bat my $runMeLine = $childLocalF . ' ' . $runMeArgC; $runMeLine = $runMeLine . ' ' . id(); $runMeLine = $runMeLine . ' ' . '>C:\Temp\81.out 2>C:\Temp\81.err +'; print "runMeLine = $runMeLine\n"; $pid = system( 1, $runMeLine ); print "XXX child PID = $pid\n"; if( $pid < 0 ) { #something went wrong with the system command. print "ERROR: System call failed\n"; print "ERROR: return value from system was $pid\n"; print "ERROR: runMeLine = $runMeLine\n"; $countSystemCallFailed++; if( $countSystemCallFailed > $cfg->{'maxSystemCallFailed'} ) { die "System call failed $countSystemCallFailed times\n"; } print "Sleeping 5 and will try again\n"; sleep( 5 ); } }

In reply to what are the common causes of "system" command failure on Vista by Workplane

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-19 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found