launch a DOS program from a Perl script?

L

Luca Villa

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
 
R

Ron Bergin

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
 
L

Luca Villa

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..
 
J

Jürgen Exner

Luca said:
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
 
R

Ron Bergin

Luca said:
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>
 
L

Luca Villa

The solution was:
perl -e "system qq'HTML2TXT $_ > '.(/(.*)html/)[0].'txt' for <c:/dir/*-
red.html>"
 
J

Jürgen Exner

Ron said:
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
 
L

Luca Villa

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top