Disclaimer: cross-posted at StackOverflow.

This is a much simpler (pure Perl) version of Debug background Perl procs started with compiled C# code (breaks only on AWS), as its far less reading, and much simpler to test/reproduce.

The issue is that on my Amazon Web Services (AWS) Windows 2012 systems, a Perl script that runs in the background listening for network requests requires an ENTER keystroke in the server script (background proc) cmd window before it processes. This does not happen on my Windows 2008 R2 systems (the proc runs properly with no interaction).

I am not certain if this is an AWS thing, or a win2k12 thing, as I don't have any 2k12 servers to test on that aren't in AWS. I'd appreciate if anyone with 2k12 systems could test this to see if it works properly.

This test does not require any non-core modules to be installed, and I've removed the requirement for Proc::Background as well.

To repro:

- copy below code to client.pl and server.pl respectively - start the server in the background: -- perl server.pl bg - run the client (different cmd window): -- perl client.pl

On my local servers, the server returns to the client properly without any interaction. On my AWS systems, it hangs. Hitting ENTER in the server cmd window causes things to go through. Running the server script in foreground mode (perl server.pl run), the whole shebang works properly on 2012 with no interaction.

NOTE: there's no method in this test code to stop the server.pl background proc. It has to be killed via Task Manager.

client.pl

use warnings; use strict; use IO::Socket::INET; use Storable; my $mod = 'IO::Socket::INET'; my $sock = new IO::Socket::INET ( PeerHost => 'localhost', PeerPort => 7800, Proto => 'tcp', ); die "can't create socket\n" unless $sock; $sock->send("cpanm $mod"); my $recv = Storable::fd_retrieve($sock); print $$recv;

server.pl

use warnings; use strict; use IO::Socket::INET; use Storable; if (@ARGV && $ARGV[0] eq 'bg'){ system 1, 'perl', $0, 'run'; } if (@ARGV && $ARGV[0] eq 'run') { my $sock = new IO::Socket::INET ( LocalHost => '0.0.0.0', LocalPort => 7800, Proto => 'tcp', Listen => 5, Reuse => 1, ); die "cannot create socket $!\n" unless $sock; while (1){ my $conn = $sock->accept; my $cmd; $conn->recv($cmd, 1024); print "executing: $cmd\n"; my $ret = `$cmd`; print "return: $ret\n"; Storable::nstore_fd(\$ret, $conn); shutdown($conn, 1); } $sock->close; }

In reply to Background proc requires ENTER keystroke on Windows 2012 by stevieb

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.