Error when combining threads and system()

Discussion in 'Perl Misc' started by Willem, Jan 8, 2010.

  1. Willem

    Willem Guest

    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
     
    Willem, Jan 8, 2010
    #1
    1. Advertising

  2. Willem

    Guest

    On Fri, 8 Jan 2010 18:51:51 +0000 (UTC), 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
    >


    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>
     
    , Jan 8, 2010
    #2
    1. Advertising

  3. Willem

    Guest

    On Fri, 08 Jan 2010 11:12:13 -0800, wrote:

    >On Fri, 8 Jan 2010 18:51:51 +0000 (UTC), 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
    >>

    >
    >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
     
    , Jan 8, 2010
    #3
  4. Willem

    Willem Guest

    wrote:
    ) On Fri, 8 Jan 2010 18:51:51 +0000 (UTC), 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
    )>
    )
    ) 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
     
    Willem, Jan 9, 2010
    #4
  5. Willem

    Guest

    On Sat, 9 Jan 2010 23:13:29 +0000 (UTC), Willem <> wrote:

    > 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
     
    , Jan 10, 2010
    #5
  6. > <> wrote:
    >
    >> I don't know what you mean my "Windows NT".


    Why doesn't that surprise anyone?

    jue
     
    Jürgen Exner, Jan 10, 2010
    #6
  7. Willem

    Willem Guest

    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
     
    Willem, Jan 10, 2010
    #7
  8. Willem

    Guest

    On Sun, 10 Jan 2010 20:07:31 +0000 (UTC), Willem <> wrote:

    > 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
     
    , Jan 10, 2010
    #8
  9. 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.
     
    Wanna-Be Sys Admin, Jan 11, 2010
    #9
  10. Willem

    Mark Guest

    On Jan 8, 10:51 am, 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
    >
    > 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.
     
    Mark, Jan 12, 2010
    #10
  11. Willem

    Willem Guest

    Mark wrote:
    ) On Jan 8, 10:51 am, 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:

    <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
     
    Willem, Jan 12, 2010
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nils Magnus Englund

    Combining forms and Windows authentication

    Nils Magnus Englund, Apr 19, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,432
    Nils Magnus Englund
    Apr 19, 2004
  2. yoda
    Replies:
    2
    Views:
    469
    =?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=
    Aug 1, 2005
  3. threads without threads

    , Aug 27, 2004, in forum: C Programming
    Replies:
    4
    Views:
    436
    William Ahern
    Aug 27, 2004
  4. Pedro Pinto

    Java Threads - Get running threads

    Pedro Pinto, Apr 8, 2008, in forum: Java
    Replies:
    2
    Views:
    1,505
    Arne Vajhøj
    Apr 9, 2008
  5. Une bévue
    Replies:
    0
    Views:
    177
    Une bévue
    Jun 14, 2006
Loading...

Share This Page