linux - write commands from one terminal to another

前端 未结 7 1601
刺人心
刺人心 2020-12-29 09:54

I need to write commands from one terminal to another terminal.

I tried these:

echo -e \"ls\\n\" > /proc/pid/fd/0
echo -e \"ls\\n\" > /dev/pts/         


        
相关标签:
7条回答
  • 2020-12-29 10:20

    Is posible to show the output of a command on multiple terminals simultaneously with the following script., and it works with all console programs, including the editors. For example doing:

    execmon.bash  'nano hello.txt' 5
    

    Open an editor and both the output and the text that we introduce will be redirected to the virtual terminal number 5. You can see your terminals:

    ls /dev/pts
    

    Each virtual terminal has an associated number.

    Is work with the normal terminal, konsole and xterm, just create the file execmon.bash and put this:

    #! / bin / bash
    # execmon.bash
    # Script to run a command in a terminal and display the output
    # in the terminal used and an additional one.
    param = $ #
    if [$ param-eq 2]; Then
        echo $ 1 | tee a.out a.out && cat> / dev / pts / $ 2 && exec `cat` a.out | tee / dev / pts / $ 2 && rm a.out
    else
        echo "Usage:"
        echo "execmon 'command' num '
        echo "-command is the command to run (you have to enter ')"
        echo "-num is the number of virtual console to output to the"
    fi
    

    Example:

    execmon.bash 'ls-l' 5
    execmon.bash 'nano Hello.txt' 5
    
    0 讨论(0)
提交回复
热议问题