This pattern works well:Then stdout will contain only the output of the command and nothing else.
set prompt ">>> "
log_user 0
send "What is quantum field theory?\r"
expect -re "(.+)$prompt"
puts -nonewline [join [lrange [lmap line [split $expect_out(1,string) \n] {regsub {\r$} $line ""}] 1 end] "\n"]
Bibliography:
- unix.stackexchange.com/questions/239161/get-the-output-from-expect-script-in-a-variable/792645#792645
- stackoverflow.com/questions/45210358/expect-output-only-stdout-of-the-command-and-nothing-else/79517903#79517903
- stackoverflow.com/questions/57975853/how-to-read-the-send-command-output-in-expect-script title is wrong, OP wants exit status apparently not stdout
The author Ole Tange answers every question about it on Stack Exchange. What a legend!
This program makes you respect GNU make a bit more. Good old make with
-j
can not only parallelize, but also take in account a dependency graph.Some examples under:
man parallel_exampes
To get the input argument explicitly job number use the magic string sample output:
{}
, e.g.:printf 'a\nb\nc\n' | parallel echo '{}'
a
b
c
To get the job number use sample output:
{#}
as in:printf 'a\nb\nc\n' | parallel echo '{} {#}'
a 1
b 2
c 3
c 3
{%}
contains which thread the job running in, e.g. if we limit it to 2
threads with -j2
:printf 'a\nb\nc\nd\n' | parallel -j2 echo '{} {#} {%}'
a 1 1
b 2 1
c 3 2
d 4 1
%
symbol in many programming languages such as C.To pass multiple CLI arguments per command you can use sample output:
-X
e.g.:printf 'a\nb\nc\nd\n' | parallel -j2 -X echo '{} {#} {%}'
a b 1 1
c d 2 2
Way too few people know about this. Spread the word.
Articles by others on the same topic
There are currently no matching articles.