Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Error when combining threads and system()

Reply
Thread Tools

Error when combining threads and system()

 
 
Willem
Guest
Posts: n/a
 
      01-08-2010
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
 
Reply With Quote
 
 
 
 
sln@netherlands.com
Guest
Posts: n/a
 
      01-08-2010
On Fri, 8 Jan 2010 18:51:51 +0000 (UTC), Willem <(E-Mail 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.
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>

 
Reply With Quote
 
 
 
 
sln@netherlands.com
Guest
Posts: n/a
 
      01-08-2010
On Fri, 08 Jan 2010 11:12:13 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

>On Fri, 8 Jan 2010 18:51:51 +0000 (UTC), Willem <(E-Mail 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.
>Do you have cmd.exe in your path?
>-sln
>


Click Start->Run, paste %SystemRoot%\system32\cmd.exe
in edit box, hit return.
Try it there.

-sln
 
Reply With Quote
 
Willem
Guest
Posts: n/a
 
      01-09-2010
(E-Mail Removed) wrote:
) On Fri, 8 Jan 2010 18:51:51 +0000 (UTC), Willem <(E-Mail 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
 
Reply With Quote
 
sln@netherlands.com
Guest
Posts: n/a
 
      01-10-2010
On Sat, 9 Jan 2010 23:13:29 +0000 (UTC), Willem <(E-Mail Removed)> wrote:

>(E-Mail 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>
-------------

Good luck!

-sln
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      01-10-2010
>(E-Mail Removed) <(E-Mail Removed)> wrote:
>
>> I don't know what you mean my "Windows NT".


Why doesn't that surprise anyone?

jue
 
Reply With Quote
 
Willem
Guest
Posts: n/a
 
      01-10-2010
(E-Mail 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
 
Reply With Quote
 
sln@netherlands.com
Guest
Posts: n/a
 
      01-10-2010
On Sun, 10 Jan 2010 20:07:31 +0000 (UTC), Willem <(E-Mail Removed)> wrote:

>(E-Mail 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)
--------

Nope, no NT 4 there.

-sln
 
Reply With Quote
 
Wanna-Be Sys Admin
Guest
Posts: n/a
 
      01-11-2010
Willem 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
>


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.

--
Not really a wanna-be, but I don't know everything.
 
Reply With Quote
 
Mark
Guest
Posts: n/a
 
      01-12-2010
On Jan 8, 10:51*am, Willem <(E-Mail 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
>
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Threads - Get running threads Pedro Pinto Java 2 04-08-2008 11:44 PM
[new to threads] threads with UI and loop Une bévue Ruby 0 06-14-2006 10:22 AM
TB View, Threads, Threads with unread The Invisible Man Firefox 1 03-20-2006 02:09 AM
Standard Threads vs Weightless Threads yoda Python 2 08-01-2005 09:12 PM
threads without threads sindica@gmail.com C Programming 4 08-27-2004 09:25 PM



Advertisments