2

I have a Matlab program that runs different unix commands fairly often. For this question let's assume that what I'm doing is:

unix('ls test')

It happens to me quite frequently that I accidentally press a key(like enter or the arrow keys) f.e. when I'm waking up my display from standby. In theory this shouldn't interfere with the unix command. Though unfortunately, Matlab will take this input and forward it right into the execution of the command. The above command then becomes something like this:

unix('ls te^[0Ast')

(Side note: ^[0A is the hex representation of the linefeed character)

Obviously, this will produce an error.

Does anyone have an idea how to work around this issue?

I was thinking that there might be a way to start Matlab with my script in a way that doesn't forward any user input from within the unix shell.

#!/bin/bash
matlab -nodisplay -nosplash -r "runMyScript();"

ユーザー入力を別の場所にパイプして、Matlab をあらゆる種類の入力から分離することはできますか?

4

1 に答える 1

2

それはあまり具体的な質問ではありませんが、試してみましょう。いくつかのオプションが表示されます。matlabはテキスト端末アプリケーションであると想定しています。

  1. nohup(1) コマンドがあります。Linuxを使用しているため、manページに次のように記載されている場合、posix以外のバージョンがある可能性があります。標準入力が端末の場合は、/ dev/nullからリダイレクトします。

    $ nohup matlab -nodisplay -nosplash -r "runMyScript();"
    
  2. /dev/null を自分でリダイレクトできます

    $ matlab -nodisplay -nosplash -r "runMyScript();" < /dev/null
    

    しかし、matlab は実際には、パイプした内容を無視して stdin を再度開くことができます (たとえば、ssh はそれを行います。echo password | ssh whereは使用できません。

  3. グラフィックス環境で実行している場合は、ウィンドウを最小化して、入力を受け取らないようにすることができます。おそらくあなたのケースではありません、あなたは自分で理解するでしょう:)

  4. 「Ctrl」、同様のキーまたはマウスを押して、ウェイクアップを試みることができます

  5. screen(1) コマンドでmatlabを実行して、画面から切断するか、別のウィンドウに切り替えることができます。Screen は、仮想端末を作成できるプログラムです (GUI の仮想デスクトップに似ています)。screen について聞いたことがない場合は、いくつかのチュートリアルを参照することをお勧めします。gnu screen チュートリアルのグーグルは、かなりの数を提供しているようです。

于 2013-05-06T13:33:51.257 に答える