I have a cpp executable which prints messages on console. when i try to execute this with tclsh, i get different behavior than sourcing on tcl console.
C++ code
#include<iostream>
int main()
{
std::cout << "Testing c++ cout from tcl sehll" << std::endl;
return 0;
}
run.tcl :
exec ./a.out
C++ message skipped/suppressed when i use "tclsh run.tcl"
.
Alternatively if I launch tcl console first with tclsh and then 'source run.tcl' message gets printed.
tclsh
% source run.tcl
Testing c++ cout from tcl sehll
I have a cpp executable which prints messages on console. when i try to execute this with tclsh, i get different behavior than sourcing on tcl console.
C++ code
#include<iostream>
int main()
{
std::cout << "Testing c++ cout from tcl sehll" << std::endl;
return 0;
}
run.tcl :
exec ./a.out
C++ message skipped/suppressed when i use "tclsh run.tcl"
.
Alternatively if I launch tcl console first with tclsh and then 'source run.tcl' message gets printed.
tclsh
% source run.tcl
Testing c++ cout from tcl sehll
Share
Improve this question
edited Mar 26 at 10:12
user2890240
asked Mar 26 at 9:32
user2890240user2890240
114 bronze badges
3
|
2 Answers
Reset to default 5From the exec
documentation (my emphasis):
If standard output has not been redirected then the
exec
command returns the standard output from the last command in the pipeline [...]
And from source
:
The return value from
source
is the return value of the last command executed in the script".
The return value is what gets printed when you run interactively.
You need to print that value in your tcl script if you want to see it, otherwise it just gets dicarded:
puts [exec ./a.out]
Using catch we can get the message.
set res [catch {exec ./a.out} msg ]
puts "$msg"
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744155246a4560828.html
tclsh run.tcl
instead. – molbdnilo Commented Mar 26 at 9:58