Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

System path

by welle (Beadle)
on Apr 30, 2011 at 11:31 UTC ( #902169=perlquestion: print w/replies, xml ) Need Help??
welle has asked for the wisdom of the Perl Monks concerning the following question:

Hi folks,

I have the following problem: I want to convert a directory PDF->TXT using a third party .exe and using system in Perl.

sub open_directory_file_pdf { my $Directory = File::Spec->canonpath( $mw->chooseDirectory() ); my $shortpath = Win32::GetShortPathName( "$Directory" ); chdir($shortpath) or die "$!"; opendir (DIR, "$shortpath") or die "$!"; my @files = grep {/.*?\.pdf/} readdir DIR; foreach my $file (@files) { system ("files/pdftotext.exe -nopgbrk -q \"$file\"" ); } close DIR; }

I get an error related to "system" -> "file" wrong written or not a command. What I am doing wrong?

PS: if I write

system ("$file" ); system ("pdftotext.exe $file");

it works fine for opening $file with the standard pdf viewer but same error when it comes to accessing the .exe.....pdftotext.exe works on command line

Replies are listed 'Best First'.
Re: System path
by elef (Friar) on Apr 30, 2011 at 18:49 UTC
    As suggested previously, try "files\\pdftotext.exe". IIRC the windows console doesn't accept / in paths to executables (it does accept it in the path of a file to be opened, don't ask why). Anyway, this means you need to use \, and then you need to escape it with another \ for perl's sake.
Re: System path
by Anonymous Monk on Apr 30, 2011 at 12:19 UTC
    I get an error related to "system" -> "file" wrong written or not a command. What I am doing wrong?

    You're not copy-ing the error message and paste-ing it in <c></c> tags :)

      just because it's German Dos... It says "file" is written wrong or the command doesn't exist

      Der Befehl "files" ist entweder falsch geschrieben oder konnte nicht gefunden werden

        As the error message suggests, it's attempting to execute a command named "files", so you could try a backslash (presuming the exe is in a subdirectory "files" — otherwise, what's the files/ supposed to be doing?)

        system ("files\\pdftotext.exe -nopgbrk -q \"$file\"" ); ^

        Not all components of Windows handle forward slashes and backslashes equivalently...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://902169]
Approved by Eliya
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2018-06-22 10:06 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.