Can I open bash from a popen() stream?

前端 未结 2 935
后悔当初
后悔当初 2021-01-19 06:46

According to the man page for popen() I am opening a /bin/sh...Is there a way I can overload this behavior to open a /bin/bash shell and interact with BASH shell scripts? O

2条回答
  •  星月不相逢
    2021-01-19 07:14

    Probably the simplest is to have a small sh script which in turn invokes your bash script like so:

    #!/bin/sh
    
    exec bash yourscript.sh "$@"
    

    Or you can forgo popen and implement your own popen with fork() and execl().

提交回复
热议问题