in reply to Re^2: Program unsuspectingly dies with no reason why.
in thread Program unsuspectingly dies with no reason why. -FIXED!

Backticks are for when you want to capture the output of some shell command. In this case, you're redirecting output to a file, so backticks won't do that. Your backticks also don't give you anything in a void context.

That said, putting the same thing in system won't help either. It's the underlying grep that's hanging.

I think that grep needs to get some arguments. You could do this, minimally:

`grep -v $removeq $sourcefile /dev/null /dev/null > $tempfile`;

That won't hang, but it also won't work until $removeq and $sourcefile are right. You probably ought to be passing them in initially:

&clean_the_file( $sourcefile, $removeq );

I can't tell what $sourcefile should be, though.

Hope this helps.

Replies are listed 'Best First'.
Re^4: Program unsuspectingly dies with no reason why.
by misconfiguration (Sexton) on Feb 14, 2008 at 15:20 UTC
    Well so far, even after passing those elements to the subprocess call "&clean_the_file();" I still had no luck. Albeit, I did remember reading about subprocess' being named with funky underscores causing issues with Perl awhile back. This may not be the case, but I removed the name of the sub() function renamed it to cleanthefile();.

    I commented everything out and just printed my variables $sourcefile and $removeq, $sourcefile prints the directory name as expected, BUT - $removeq spits this output out
    [root@oailxpp02 ccsys]# /root/mkpq -r queue-04 Global symbol "$removeq" requires explicit package name at /root/mkpq +line 87. Execution of /root/mkpq aborted due to compilation errors.

    My guess is: the scalar isn't being handled properly, the subprocess can't bring it into it's set of instructions, am I on the right track? Does anyone have any recommendations?

      The error "Global symbol "$removeq" requires explicit package name" is what you get (under strict) when you try to use a variable named $removeq without declaring it with my. In the code you posted originally, there is a my declaration for $removeq, so I don't know why you'd be getting this error now. I'd need to know what else is changed. Maybe you could post an updated copy of the code you're using.

        Updated code
        if ($remove) { $remove = lc($remove); my %remove_cmd = ( remove => "rmquedev -d $remove -q $remove" ); print "Are you sure you want to remove print queue \"$remove\" [Y/ +n]?"; $_ = <>; chomp($_); $_ = "Y" if ( length($_) == 0 ); if ( $_ =~ /[Yy]/ ) { # Wait for user-input system( $remove_cmd {'remove'} ); print "Prepairing to remove \"$remove\" from the CC_print.printers file.\n"; sleep 2; my $removeq = $remove; &cleanthefile($removeq); } else { die "You chose NOT to remove queue \"$remove\"\n"; } }

        Sub-Process
        sub cleanthefile { my $sourcefile = "/u/ccsys/CC_print.printers"; print $removeq; print "$sourcefile\n"; # Keep a dedicated backup of CC_print.printers if ( -t ne "/root/CC_print.printers.bkp" ) { system("touch /root/CC_print.printers.bkp"); sleep 2; system("cp -R $sourcefile /root/CC_print.printer.bkp"); } if ( -t eq "/root/CC_print.printers.bkp" ) { system("cp -R $sourcefile /root/CC_print.printer.bkp"); # grab the sourcefile and the string to remove as the first and second + arguments my ( $sourcefile, $removeq )= @_; my $tempfile = "/u/ccsys/CC_print.printers.bkp_mkpq"; # create a temporary file if (-e ne "$tempfile") { system("touch /u/ccsys/CC_print.printers.bkp_mkpq"); } # extract lines from $sourcefile which do NOT have the string to + remove # note that the \' inserts ticks so that strings with spaces can + work, too if ( -t "$tempfile") { #system ("cat $sourcefile \| grep -v $removeq $sourcefile > $t +empfile"); #`grep -v $removeq $sourcefile /dev/null /dev/null > $tempfile +`; sleep 1; print "Waiting to unlink..\n"; # delete source file, then rename working file unlink($sourcefile); rename( $tempfile, $sourcefile ); system("rm -rf $tempfile"); } } }

        I placed a print statment for $removeq to me it seems as if $removeq is not being passed correctly. I'm rather new to Perl, I wouldn't doubt this is just product of my inexperience with programming in general. No matter how much I read I can't seem to find a solution to this issue!