Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

IPC::Run and Win32::Process::Create

by jpavel (Sexton)
on Jul 09, 2004 at 16:02 UTC ( [id://373184]=perlquestion: print w/replies, xml ) Need Help??

jpavel has asked for the wisdom of the Perl Monks concerning the following question:

Gracious Monks -

I've tired of the monotony of transferring files and node-hopping in our complex environment from my WinXP workstation, so I've begun scripting solutions. It's got a Win32::GUI interface (due to Tk conflicts) and am using IPC::Run to interact with plink and pscp (command line SSH/SCP programs). Plink works perfectly; as I began scripting pscp, I've come across an oddity. If the file I want to transfer is not in the directory as the script, IPC::Run fails, citing "caught Bad file descriptor: Win32::Process::Create() at C:/Perl/site/lib/IPC/Run.pm line 2799".

The error occurs with the file selection; not even in passing the file to IPC::Run (meaning, if I have a file selected that is not in the directory, IPC::Run's "start" will fail, even if the file reference isn't passed or used by IPC::Run by that point in time). I'm imagining there is some conflict in the packages, but I'm clueless in troubleshooting this, and hoped someone had seen something like it before. Snippets below.

To select the file:
my $file = "\0" . " " x 256; $scpfile->Text(GUI::GetOpenFileName(-title=>'SCP',-file=>"\0" . " " x +256,-filter => [ "All files", "*.*" ]));
And the IPC::Run incantation:
my $host = $reds->GetString($reds->SelectedItem()); my @cmd = ( "pscp", "-pw", $redpass->Text(), Win32::GetShortPathName($ +scpfile->Text()), $userid.'@'.$host.':'.$redscp->Text() ) ; my ($in, $out, $err); my $h = start \@cmd, \$in, \$out, \$err, debug => 2; while ($out !~ /100/) {print $out;pump $h;} finish $h or die "returned $?";
Is there a conflict in these packages, or am I doing something foolish (besides poorly written code!)??

Thanks in advance...

Replies are listed 'Best First'.
Re: IPC::Run and Win32::Process::Create
by jpavel (Sexton) on Jul 09, 2004 at 17:44 UTC
    Update: seems like this workaround is pretty solid...
    my $file = Win32::GetShortPathName($scpfile->Text()); $file =~ /(.*\\).*$/; print "CD to $1\n"; Win32::SetCwd($1);
    Not the prettiest bit of code, but I wanted to see if the cwd could be to blame. I still don't get why I have this problem in the first place; I pass the absolute path to the file (works from a direct command line incantation of pscp). This workaround means I have to send the absolute path to pscp now, but no biggie there. If anyone can explain what I ran into with this, please let me know!!

      I suspect that the error text caught Bad file descriptor: Win32::Process::Create()... is unrelated to the problem you were having. Your probably still getting that msg even with your work-around. It is probably benign.

      It would be interesting to substitute a .bat file for the PSPC command and see what the actual parameters that are being received by the called program are (prior to your fix), along with the cwd at that point.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
      "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon
Re: IPC::Run and Win32::Process::Create
by BrowserUk (Patriarch) on Jul 09, 2004 at 17:04 UTC

    Try setting set IPCRUNDEBUG=gory prior to running your program and see if that provides a few more details about the problem.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon
      Unfortunately, with all levels of debug, I get the same part of interest. Everything behaves as a successful transaction until it spawns the cmd line...
      IPC::Run 0011 0123456789012 [#1(3072)]: cmd line: .\pscp.EXE -pw ***** +**** C:\Admin\********* jpavel@********:/scratch/jpavel/ IPC::Run 0011 0123456789012 [#1(3072)]: caught Bad file descriptor: Wi +n32::Process::Create() at C:/Perl/site/lib/IPC/Run.pm line 2799
      I can post more of the debug output if you think it'll be helpful.

        Are there any lines that begin

        Win32 optimizer:...
        ?

        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://373184]
Approved by jfroebe
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (1)
As of 2024-04-24 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found