Error when combining threads and system()

W

Willem

Hi,

I'm having a weird problem involving threads and calls to system()

Note: it only fails on some systems, notably a Windows NT 2003 server.

The issue is that when I call system() in the main thread, everything works
like it should, but when I call it in a subthread, it fails with the
following message:

Can't spawn "cmd.exe": No such file or directory at test-bug.pl line 10.
foo

This is the test program as minimal as I could get it:

use warnings;
use strict;
use threads;
threads->create(\&tests)->join();
tests();
sub tests { system('echo foo') }

It fails on both perl 5.8.8 built for MSWin32-x86-multi-thread
and perl 5.10.x, using Activestate.

The value of $? seems to be 255<<8, so that's a return code
of -1 from the shell.

Piped open fails as well, as do backticks. Probably for the same reason.
Can anyone shed any light on this ? I've tried googling, but I haven't
found anything specific to threading.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
S

sln

Hi,

I'm having a weird problem involving threads and calls to system()

Note: it only fails on some systems, notably a Windows NT 2003 server.

The issue is that when I call system() in the main thread, everything works
like it should, but when I call it in a subthread, it fails with the
following message:

Can't spawn "cmd.exe": No such file or directory at test-bug.pl line 10.
foo

Works on XP.
Do you have cmd.exe in your path?
-sln

use warnings;
use strict;
use threads;

threads->create(\&tests)->join();
tests();
sub tests { system('echo foo') }

__END__

c:\temp>perl -v

This is perl, v5.10.0 built for MSWin32-x86-multi-thread
(with 5 registered patches, see perl -V for more detail)

Copyright 1987-2007, Larry Wall

Binary build 1004 [287188] provided by ActiveState http://www.ActiveState.com
Built Sep 3 2008 13:16:37

c:\temp>perl cc.pl
foo
foo

c:\temp>
 
W

Willem

(e-mail address removed) wrote:
)
)>Hi,
)>
)>I'm having a weird problem involving threads and calls to system()
)>
)>Note: it only fails on some systems, notably a Windows NT 2003 server.
)>
)>The issue is that when I call system() in the main thread, everything works
)>like it should, but when I call it in a subthread, it fails with the
)>following message:
)>
)> Can't spawn "cmd.exe": No such file or directory at test-bug.pl line 10.
)> foo
)>
)
) Works on XP.

As I said above, it only fails on Windows NT.

) Do you have cmd.exe in your path?

Obviously, otherwise the main thread would have failed as well.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
S

sln

(e-mail address removed) wrote:
) Works on XP.

As I said above, it only fails on Windows NT.

) Do you have cmd.exe in your path?

Obviously, otherwise the main thread would have failed as well.


SaSW, Willem

I don't know what you mean my "Windows NT".
3.5, 3.51, 4.0, W2k, 2003, XP ?

Seriously, 2003 = XP + W2k Server.

Since I have Windows 2000 Server, I just installed ActiveStates Perl
from the "ActivePerl-5.10.0.1004-MSWin32-x86-287188.zip" file on my
W2k server. The results were the same, worked just like it did on XP.

There may be a different installation file for 2003 server though (didn't check).

You stated 5.8 works ok, 5.10 does not. Some things you should try:
- Completely remove one version before installing/testing another.
- Read the 'Release.txt' of the installation for known issues/incompatabilities.
- Check with ActiveState on this, report a possible bug on http://bugs.activestate.com.
- Do a clean install of 2003 server on a spare machine. Take all the defaults, don't
install IIS/Ftp or any extra services. Install Perl 5.10, try your code again.

If there hasn't been any reports of this (it would have come up by now), these
are what ActiveState would suggest to you.

Finally, the AS install's seem to put a lot of registry entries in. These are mostly
installation location and version information, some have class id's.
If you don't want to clean out the registry between installs, the proper way to
go from one version to another (and back) is to designate (keep) the same path to
Perl for each install, renaming the directory to \Perl5.8.8 or something, before
installing the other version. But you have to run the install every time to let
it rewrite the registry entries (for versioning), and at the same time its keeping
paths and such valid.

I would personally run the uninstall each time. The search the registry for 'ActiveState'
or 'ActivePerl', then cleaning those entries out. Then install.

I don't know if you can create restore points in 2003, that may be a way to
snapshot the registry before install, getting back when you need to.

If your code works after this, then you have some other problems.
Without any evidence, no way would I flat out blame the OS or installation.

But there is a problem, or you wouldn't have said it otherwise...

-------------
C:\temp>ver

Microsoft Windows 2000 [Version 5.00.2195]

C:\temp>type cc.pl
use warnings;
use strict;
use threads;

threads->create(\&tests)->join();
tests();
sub tests { system('echo foo') }


C:\temp>perl cc.pl
foo
foo

C:\temp>perl -v

This is perl, v5.10.0 built for MSWin32-x86-multi-thread
(with 5 registered patches, see perl -V for more detail)

Copyright 1987-2007, Larry Wall

Binary build 1004 [287188] provided by ActiveState http://www.ActiveState.com
Built Sep 3 2008 13:16:37

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

C:\temp>
 
W

Willem

(e-mail address removed) wrote:
) I don't know what you mean my "Windows NT".
) 3.5, 3.51, 4.0, W2k, 2003, XP ?

Windows NT 4.00.1381

I was wrong about the 2003 bit.

) You stated 5.8 works ok, 5.10 does not. Some things you should try:

No I didn't. I stated it fails to work on _both_ 5.8 and 5.10.
Furthermore you seem to be completely ignoring the crux of the problem:

It works in the main thread and fails in the subthread.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
S

sln

(e-mail address removed) wrote:
) I don't know what you mean my "Windows NT".
) 3.5, 3.51, 4.0, W2k, 2003, XP ?

Windows NT 4.00.1381

I was wrong about the 2003 bit.

) You stated 5.8 works ok, 5.10 does not. Some things you should try:

No I didn't. I stated it fails to work on _both_ 5.8 and 5.10.
Furthermore you seem to be completely ignoring the crux of the problem:

It works in the main thread and fails in the subthread.


SaSW, Willem

You were wrong about the 2003 bit?
NT 4, goes back a long ways and hasn't been
supported in quite a while, years in fact.
Maybe you should use a distribution from that timeframe.

--------
ActivePerl 1004 -- Release Notes
Welcome, and thank you for downloading ActivePerl. This release
corresponds to Perl version 5.10.

The following platforms are supported by this release:

* AIX 5.1 or later (rs6000)

* Linux: glibc 2.3 or later (x86 and x64)

* Mac OS X 10.4 or later (x86 and powerpc)

* Solaris 2.8 or later (sparc, 32 and 64 bit)

* Solaris 10 or later (x86)

* Windows 2000 (x86)

* Windows XP, 2003, Vista (x86 and x64)
 
W

Wanna-Be Sys Admin

Willem said:
Hi,

I'm having a weird problem involving threads and calls to system()

Note: it only fails on some systems, notably a Windows NT 2003 server.

The issue is that when I call system() in the main thread, everything
works like it should, but when I call it in a subthread, it fails with
the following message:

Can't spawn "cmd.exe": No such file or directory at test-bug.pl line
10. foo

I haven't used Windows in years and years, I'm glad to say, but I'd be
curious if there's any difference for $PATH in the sub thread.
 
M

Mark

Hi,

I'm having a weird problem involving threads and calls to system()

Note: it only fails on some systems, notably a Windows NT 2003 server.

The issue is that when I call system() in the main thread, everything works
like it should, but when I call it in a subthread, it fails with the
following message:

  Can't spawn "cmd.exe": No such file or directory at test-bug.pl line 10.
  foo

This is the test program as minimal as I could get it:

  use warnings;
  use strict;
  use threads;
  threads->create(\&tests)->join();
  tests();
  sub tests { system('echo foo') }

It fails on both perl 5.8.8 built for MSWin32-x86-multi-thread
and perl 5.10.x, using Activestate.

The value of $? seems to be 255<<8, so that's a return code
of -1 from the shell.

Piped open fails as well, as do backticks.  Probably for the same reason.
Can anyone shed any light on this ?  I've tried googling, but I haven't
found anything specific to threading.

SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


I was unable to recreate the problem on my W2003 server with perl
5.8.6 and this may be reaching but it could be a file security issue
with cmd.exe.

Non-administrator interactive users have Read+Execute permission on
%SystemRoot%\system32\cmd.exe. But, if the system has classified your
process thread as non-interactive and not in the Administrators group,
the thread will not have read access to cmd.exe which would account
for the "No such file or directory" error. Check out the permissions
on cmd.exe and note the special "INTERACTIVE" group and the
permissions assigned.

You might try adding Read+Execute permisson to cmd.exe for whatever
user context the thread runs under. If it works then it's a
permission problem and you can go from there.
 
W

Willem

Mark wrote:
)> Hi,
)>
)> I'm having a weird problem involving threads and calls to system()
)>
)> Note: it only fails on some systems, notably a Windows NT 2003 server.
)>
)> The issue is that when I call system() in the main thread, everything works
)> like it should, but when I call it in a subthread, it fails with the
)> following message:

<snip>

) I was unable to recreate the problem on my W2003 server with perl
) 5.8.6 and this may be reaching but it could be a file security issue
) with cmd.exe.
)
) Non-administrator interactive users have Read+Execute permission on
) %SystemRoot%\system32\cmd.exe. But, if the system has classified your
) process thread as non-interactive and not in the Administrators group,
) the thread will not have read access to cmd.exe which would account
) for the "No such file or directory" error. Check out the permissions
) on cmd.exe and note the special "INTERACTIVE" group and the
) permissions assigned.
)
) You might try adding Read+Execute permisson to cmd.exe for whatever
) user context the thread runs under. If it works then it's a
) permission problem and you can go from there.

That sounds very plausible. Since then, I've had the same problem with
running a service (PerlSvc) which gave similar errors on trying to execute
backtick or pipe-open commands. Also only on that WinNT4.0 server.

I'll look into it tomorrow, thanks for the hint!


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top