in reply to Re: Using System command
in thread Using System command

I suspect that if you print your $cmd you'll see why:

cd C:\\ABC\\pdftotext -layout R1.pdf

Probably is not what you want to execute.

Perl has a builtin to change directory: chdir

In the command line, two commands have to been concatenated with & or && (NB: the latter && only execute the second command if the previous was succesfull ms odcs)

See a more userfriendly explaination at ss64.com for details.

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^3: Using System command
by 9mohit2 (Sexton) on Oct 04, 2016 at 09:06 UTC

    Tried the below code

    my $cmd = "cd C:\\ABC\\"; my $cmd1 = "pdftotext -layout R1.pdf"; system($cmd&&$cmd1);

    But the error this time is "'pdftotext' is not recognized as an internal or external command, operable program or batch file"

      What is the following code supposed to mean?

      system($cmd&&$cmd1);

      Maybe you wanted something like:

      my $real_command = "$cmd && $cmd1"; warn "Running [$real_command]"; system($real_command) == 0 or die "Couldn't launch [$real_command]: $? / $!";

      Observe the difference between

      my $real_command = "$cmd && $cmd1"; print $real_command; # and my $real_command = $cmd && $cmd1; print $real_command;

        Thanks a lot for that clarification @gods. It is giving proper results now with the use of quotes "" in the to form the final command.

        system("$cmd && $cmd1");
      Wait, the && here is the shell operator, not the Perl one, so it should be

      0 == system "$cmd && $cmd1" or die "Error: $?";
      As $cmd was true, the result of $cmd && $cmd1 in Perl was just $cmd .

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,