View previous topic :: View next topic |
Author |
Message |
l3u Advocate
Joined: 26 Jan 2005 Posts: 2546 Location: Konradsreuth (Germany)
|
Posted: Tue Jun 14, 2005 4:35 pm Post subject: [OT] Andere Programme von PERL aus benutzen |
|
|
Ich hab mal eine Grundsätzliche Frage. Wie stell ich es an, in einem PERL-Script Programme wie oggdec oder lame, etc. zu benutzen, und den aktuellen Fortschritt zu bekommen? Also quasi das externe Programm läuft im Hintergrund und ich kann irgendwas mit dem Prozent-Wert in dem PERL-Programm machen. |
|
Back to top |
|
|
Deever Veteran
Joined: 06 Jul 2002 Posts: 1354 Location: Zürich / Switzerland
|
Posted: Wed Jun 15, 2005 6:17 am Post subject: |
|
|
Also in C würd ich popen() benutzen, vermutlich geht das in PERL ähnlich.
Gruß,
/dev |
|
Back to top |
|
|
Anarcho Advocate
Joined: 06 Jun 2004 Posts: 2970 Location: Germany
|
|
Back to top |
|
|
l3u Advocate
Joined: 26 Jan 2005 Posts: 2546 Location: Konradsreuth (Germany)
|
Posted: Wed Jun 15, 2005 11:37 am Post subject: |
|
|
Hmmm ... ich krieg's nicht hin. Wie ich den gesamten Output eines Programmes abfange, ist mir schon klar ... aber wie kann ich z.B. die prozentuale Fortschrittsanzeige von oggdec benutzen, während oggdec noch läuft? |
|
Back to top |
|
|
Mankale Tux's lil' helper
Joined: 20 Jan 2004 Posts: 76
|
Posted: Wed Jun 15, 2005 9:20 pm Post subject: |
|
|
bin kein Perl coder, aber ich würde versuchen stdout des externen Programms zu öffnen und dann Zeile für Zeile zu lesen.
So gehts zumindest in php |
|
Back to top |
|
|
l3u Advocate
Joined: 26 Jan 2005 Posts: 2546 Location: Konradsreuth (Germany)
|
Posted: Tue Jun 28, 2005 8:32 pm Post subject: |
|
|
Das Problem war, daß die ganzen Zeilen mit prozent-Fortschritt als nur eine ausgelesen wurde. War daran gelegen, daß die Zeilenbegrenzung mit "\n" definiert war. Kann man auf "\r" umdefinieren, dann bekommt man alle Zeilen. |
|
Back to top |
|
|
Silicoid Tux's lil' helper
Joined: 20 Jul 2004 Posts: 144 Location: Erde
|
Posted: Wed Jun 29, 2005 5:29 pm Post subject: |
|
|
Aus "perlvar":
Code: |
$INPUT_RECORD_SEPARATOR
$RS
$/ The input record separator, newline by default. This influ-
ences Perl's idea of what a "line" is. Works like awk's RS
variable, including treating empty lines as a terminator if set
to the null string. (An empty line cannot contain any spaces
or tabs.) You may set it to a multi-character string to match
a multi-character terminator, or to "undef" to read through the
end of file. Setting it to "\n\n" means something slightly
different than setting to "", if the file contains consecutive
empty lines. Setting to "" will treat two or more consecutive
empty lines as a single empty line. Setting to "\n\n" will
blindly assume that the next input character belongs to the
next paragraph, even if it's a newline. (Mnemonic: / delimits
line boundaries when quoting poetry.)
local $/; # enable "slurp" mode
local $_ = <FH>; # whole file now here
s/\n[ \t]+/ /g;
Remember: the value of $/ is a string, not a regex. awk has to
be better for something. :-)
Setting $/ to a reference to an integer, scalar containing an
integer, or scalar that's convertible to an integer will
attempt to read records instead of lines, with the maximum
record size being the referenced integer. So this:
local $/ = \32768; # or \"32768", or \$var_containing_32768
open my $fh, $myfile or die $!;
local $_ = <$fh>;
will read a record of no more than 32768 bytes from FILE. If
you're not reading from a record-oriented file (or your OS
doesn't have record-oriented files), then you'll likely get a
full chunk of data with every read. If a record is larger than
the record size you've set, you'll get the record back in
pieces.
On VMS, record reads are done with the equivalent of "sysread",
so it's best not to mix record and non-record reads on the same
file. (This is unlikely to be a problem, because any file
you'd want to read in record mode is probably unusable in line
mode.) Non-VMS systems do normal I/O, so it's safe to mix
record and non-record reads of a file.
See also "Newlines" in perlport. Also see $..
|
|
|
Back to top |
|
|
|