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

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

Comment on System path
Select or Download Code
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...

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://902169]
Approved by Eliya
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2014-08-28 12:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (259 votes), past polls