Dear Experts, I have been testing a simple portion of a script that is supposed to become part of something else and suddenly run into a problem: after I delete the Vmware Workstation snapshot using system() I get Bad file descriptor message. But the snaphot itself is successfully deleted! And the same command from the command prompt works all right. Here is my code:

#!/usr/bin/perl use Time::HiRes; use File::Path; use warnings; use strict; $|=1; sub spin { my ($arg) = @_; for (my $x = 0; $x <= $arg; ++$x) { foreach (("-", "\\", "|", "/")) { print $_; Time::HiRes::sleep (0.1); print "\b"; } } #print " \n"; } my $j = 0; my $base = "C:/Users/User/Documents/Virtua~1/"; print "Enter VM name: "; my $vm = <STDIN>; chomp ($vm); print "Enter Snapshot to be deleted: "; my $snapshot = <STDIN>; chomp ($snapshot); my $vmware_dir = "C:/Progra~2/Vmware/VMware~1/"; my $command = "$vmware_dir" . "vmrun -T ws deleteSnapshot " . "$base" +. "$vm" . "/" . "$vm" . ".vmx " . "$snapshot"; if ( (my $pid = fork() ) == 0) { do { sleep 0.5; spin($j) } while 1; } else { print "Deleting snapshot..."; system ("$command") or die "Operation failed: $!\n"; kill 9, $pid; waitpid $pid, 0; } print "\bDone!\n"; # Never gets here!

And this is what I get in the end:

Deleting snapshot...\Operation failed: Bad file descriptor

As I said, the snapshot gets deleted, but there is an error message and the background spinning never ends.
Thank you in advance!


In reply to Bad file descriptor after vmran command using system() by Ingvar

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.