运行 kdb 中的一个系统命令

running a system command in kdb

我正在尝试 运行 kdb 中的命令,但它不起作用。我知道它可能与某些特殊字符有关,我试图将 [] 转义但仍然不起作用。

system "awk '/^Mem/ {print }' <(free -m)"

我试过了

system "awk '/[^]Mem/ {print }' <(free -m)"  - not working

如有任何意见,我们将不胜感激。

您可以避免系统调用,因为 kdb+ 可以 return 使用 .Q.w[]

可用的物理内存
q)floor (.Q.w[]`mphy)%1024 xexp 2
28072
\
$ awk '/^Mem/ {print }' <(free -m)
28072

另一个解决方案只需要重新排列您的表达式:

q)system"free -m | awk '/^Mem/ {print }'"
"25408"

编辑:

你的表达式从 q 失败的原因是因为使用了 shell。 This answer 解释了 shebang 和破折号之间的区别 shells。我添加了一些测试来展示差异。

coneill5@LPTP1893: [~] $ cat test.sh
#!/bin/bash
awk '/^Mem/ {print }' <(free -m)
coneill5@LPTP1893: [~] $ cat test1.sh
#!/bin/sh
awk '/^Mem/ {print }' <(free -m)
coneill5@LPTP1893: [~] $ ./test.sh
25408
coneill5@LPTP1893: [~] $ ./test1.sh
./test1.sh: 2: Syntax error: "(" unexpected