How to execute system commands in the current shell instance
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I am using Matlab 7.8.0.347 (R2009a) on a Linux cluster. I use functions "system" and "unix" execute Unix commands, sometimes as simple as 'ls'.
However, these functions execute the command in a new shell, so what is actually executed is not only the command but also the login scripts, with the associated waste of time and resources. This can easily tested by including an 'echo world' line in the login files (e.g. .profile).
Is it possible to execute a command directly as a child process without an intervening shell process?
Thank you in advance,
Alessandro
0 个评论
回答(1 个)
Walter Roberson
2012-7-17
It is the responsibility of those profiles to test to see whether they are being used in interactive form or not.
In shells derived from the Bourne shell, the usual way to do this is with the "-t" test.
if [[ -t 0 ]] #then stdin is associated with a terminal, indicating interactive use
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Software Development Tools 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!