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

I'm having problems returning from a batch file called by the system command. The batch file completes but never returns to the calling perl script. What am I missing here? Here's a snippet of my code:

newbug.bat:

@echo off echo this is some message echo another message echo yet another message goto fini :fini echo "Exiting..." exit /b

fascanner.pl:

... $Jira_command_line="newbug $Jira_bug_category $Jira_bug_number trunk $ +TRUNK $sernum"; print "Calling '$Jira_command_line'\n"; #$i = system("$Jira_command_line"); ### original line but doesn't wor +k $i = system("cmd /c $Jira_command_line"); ### this also doesn't work print "\n********** Initial FA of $sernum complete! **********\n";

I noticed that "Exiting..." is displayed so it should be exiting, but somewhere hangs between leaving the batch file and returning to my perl script. Any ideas why? Thanks for your help.

I'm running ActivePerl 5.12 on Win XP and I've also tried ActivePerl 5.14, but still have the same issue.

Replies are listed 'Best First'.
Re: Not returning from batch file
by ikegami (Patriarch) on Aug 17, 2011 at 18:36 UTC
    I cannot replicate, but I used Win7. I'd be happier if you actually posted runnable code. ("..." is a syntax error...)

      I added the ... to mean there's other code above the code I entered.

        Which means it still won't run if I remove the "...". Like I said, you didn't post runnable code.

        The real problem is that the output you describe does not originate from code you posted. Reduce the code to something minimal first, *then* post *this* code's output.

Re: Not returning from batch file
by Gulliver (Monk) on Aug 17, 2011 at 20:03 UTC

    'exit /b' exits the script but not the command interpreter according to 'help exit'. Sounds to me like Perl is waiting for cmd to die. Remove 'exit /b' and try again or close out the new command box opened by the batch file and see if your Perl script starts again.

    Update: I just tried it with a toy version and like ikegami I don't see the problem. I'm using XP. I was mistaken in thinking system() opened another dos box.

      exit /b will only exit the batch file, not the whole interpreter, but the interpreter is set to exit once the batch exits. exit and exit /b have the same effect here.

Re: Not returning from batch file
by RichardK (Parson) on Aug 18, 2011 at 11:32 UTC

    Might your problem be that system expects a list not a string?

    I've had system do odd things in the past due to that!

    you could try something like this

    my @Jira_command_line= qw/newbug $Jira_bug_category $Jira_bug_number trunk $TRUNK $sernum/; print "Calling '",join(',',@Jira_command_line),"'\n"; $i = system(@Jira_command_line);

    BTW Not Tested at all as I don't run windows here.