2

我正在我的 ROOT 代码中执行一个 shell 命令,使用gSystem它返回一个int,如此处所示gSystem->Exec()。但是当我尝试将输出分配给代码变量时,分配不会发生。

int low_edge = 0;
low_edge = gSystem->Exec("ls ./folder | egrep -o '[0-9]{3,3}' | head -1");

我也试过gSystem->Exec("ls ./folder | egrep -o '[0-9]{3,3}' | head -1") >> low_edge了,但没有成功。

我错过了一些明显的东西吗?

4

1 回答 1

0

gSystem->Exec() 的返回值是 0 或 -1,具体取决于命令是否成功。

你想要的是:

TString GetFromPipe(const char* 命令)

TString the_output=gSystem->GetFromPipe("ls ./folder | egrep -o '[0-9]{3,3}' | head -1");

应该可以工作,您只需要将 TString 转换为 int。

于 2015-06-12T08:16:35.643 回答