How to execute system commands in the current shell instance

1 回表示 (過去 30 日間)
Ale
Ale 2012 年 7 月 17 日
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

回答 (1 件)

Walter Roberson
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

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by