launch a DOS program from a Perl script?

Discussion in 'Perl Misc' started by Luca Villa, Nov 10, 2007.

  1. Luca Villa

    Luca Villa Guest

    Can I launch a DOS program from within a Perl script?

    ____

    This is what I need to do:

    I have many files like this:
    c:\dir\pippo-red.html
    c:\dir\paperino-yellow.html
    c:\dir\pluto-red.html
    c:\dir\gastone-green.html

    I have a HTML2TXT.EXE program that converts files from html to txt
    (removing the tags etc...).

    The syntax of this program is: "HTML2TXT htmlfilename.htm >
    txtfilename.txt"

    I want to convert all and only the file which path-name match "c:\dir
    \*-red.html". The output files must have the suffix "-text" in the
    filename and ".txt" as extension.

    In a few words the Perl script in this example must execute the
    command two times like this:
    HTML2TXT c:\dir\pippo-red.html > c:\dir\pippo-red-text.txt
    HTML2TXT c:\dir\pluto-red.html > c:\dir\pluto-red-text.txt


    Do you know how can I do this?


    Thanks in advance for any help
     
    Luca Villa, Nov 10, 2007
    #1
    1. Advertising

  2. Luca Villa wrote:
    > Can I launch a DOS program from within a Perl script?


    perldoc -f system
    perldoc -f qx

    jue
     
    Jürgen Exner, Nov 11, 2007
    #2
    1. Advertising

  3. Luca Villa

    Ron Bergin Guest

    On Nov 10, 3:30 pm, Luca Villa <> wrote:
    > Can I launch a DOS program from within a Perl script?
    >
    > ____
    >
    > This is what I need to do:
    >
    > I have many files like this:
    > c:\dir\pippo-red.html
    > c:\dir\paperino-yellow.html
    > c:\dir\pluto-red.html
    > c:\dir\gastone-green.html
    >
    > I have a HTML2TXT.EXE program that converts files from html to txt
    > (removing the tags etc...).
    >
    > The syntax of this program is: "HTML2TXT htmlfilename.htm >
    > txtfilename.txt"
    >
    > I want to convert all and only the file which path-name match "c:\dir
    > \*-red.html". The output files must have the suffix "-text" in the
    > filename and ".txt" as extension.
    >
    > In a few words the Perl script in this example must execute the
    > command two times like this:
    > HTML2TXT c:\dir\pippo-red.html > c:\dir\pippo-red-text.txt
    > HTML2TXT c:\dir\pluto-red.html > c:\dir\pluto-red-text.txt
    >
    > Do you know how can I do this?
    >
    > Thanks in advance for any help


    It's proper ediquite to inform people that you've posted this question
    in multiple forums and have received the solution.
    http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q_22952500.html
     
    Ron Bergin, Nov 11, 2007
    #3
  4. Luca Villa

    Luca Villa Guest

    This seems to be the solution:
    system "HTML2TXT $_ > ".(/(.*)html/)[0]."txt" for <c:/dir/*-red.html>;

    but how can I launch it from command-line?
    I tried PERL 'system "HTML2TXT $_ > ".(/(.*)html/)[0]."txt" for <c:/
    dir/*-red.html>;' without success...
    sorry for my incompetence..
     
    Luca Villa, Nov 11, 2007
    #4
  5. Luca Villa wrote:
    > This seems to be the solution:
    > system "HTML2TXT $_ > ".(/(.*)html/)[0]."txt" for <c:/dir/*-red.html>;


    Well, I am not to argue with you but that is not even valid Perl code:
    <quote>
    Bareword found where operator expected at t.pl line 5, near "<c:/>dir"
    (Missing operator before dir?)
    Bareword found where operator expected at t.pl line 5, near "*-red"
    (Missing operator before red?)
    syntax error at t.pl line 5, near "<c:/>dir"
    t.pl had compilation errors.
    <\quote>
    You may want to fix that first.

    jue
     
    Jürgen Exner, Nov 11, 2007
    #5
  6. Luca Villa

    Ron Bergin Guest

    On Nov 11, 8:22 am, "Jürgen Exner" <> wrote:
    > Luca Villa wrote:
    > > This seems to be the solution:
    > > system "HTML2TXT $_ > ".(/(.*)html/)[0]."txt" for <c:/dir/*-red.html>;

    >
    > Well, I am not to argue with you but that is not even valid Perl code:
    > <quote>
    > Bareword found where operator expected at t.pl line 5, near "<c:/>dir"
    > (Missing operator before dir?)
    > Bareword found where operator expected at t.pl line 5, near "*-red"
    > (Missing operator before red?)
    > syntax error at t.pl line 5, near "<c:/>dir"
    > t.pl had compilation errors.
    > <\quote>
    > You may want to fix that first.
    >
    > jue


    It might help if you type in the command correctly when testing.

    <c:/>dir/*-red.html>

    is not the same as

    <c:/dir/*-red.html>
     
    Ron Bergin, Nov 11, 2007
    #6
  7. Luca Villa

    Luca Villa Guest

    The solution was:
    perl -e "system qq'HTML2TXT $_ > '.(/(.*)html/)[0].'txt' for <c:/dir/*-
    red.html>"
     
    Luca Villa, Nov 11, 2007
    #7
  8. Ron Bergin wrote:
    > On Nov 11, 8:22 am, "Jürgen Exner" <> wrote:
    >> t.pl had compilation errors.
    >> <\quote>
    >> You may want to fix that first.
    >>
    >> jue

    >
    > It might help if you type in the command correctly when testing.
    >
    > <c:/>dir/*-red.html>
    >
    > is not the same as
    >
    > <c:/dir/*-red.html>


    Indeed. Copy-and-paste error of the oversized line.
    My mistake.

    jue
     
    Jürgen Exner, Nov 11, 2007
    #8
  9. Luca Villa

    Luca Villa Guest


    > Do you need to use Perl? Use plain old DOS?
    >
    > for %F in (c:\dir\*-red.html) do HTML2TXT "%F" > "%~dF%~pF%~nF.txt"


    Genial!

    I'm very happy that there is still someone on this earth that master
    DOS/BATCH commands.

    Thank you VERY VERY much Len! I'll use your solution!

    "for /?" revealed an hidden treasure

    BTW are there any active communities/forums/message boards on the web
    to discuss DOS/BATCH commands?
     
    Luca Villa, Nov 11, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Fairbank
    Replies:
    2
    Views:
    5,460
  2. john san
    Replies:
    19
    Views:
    743
    Diez B. Roggisch
    Feb 18, 2005
  3. tomhr
    Replies:
    27
    Views:
    1,421
    Mike Wahler
    Jan 12, 2006
  4. Replies:
    6
    Views:
    545
  5. Robert Wallace

    my own perl "dos->unix"/"unix->dos"

    Robert Wallace, Jan 21, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    281
    Michele Dondi
    Jan 22, 2004
Loading...

Share This Page