dougu1896 2016-07-07 18:20
浏览 66

通过网页在shell可执行文件中运行多个命令

I am trying to send commands to the bash shell through a webpage and echo the results to the webpage. The php echo '....' command works great to output the results of terminal commands.

My C program acts like a terminal itself, in that it continuously prompts the user for input and spits out the corresponding data correlating to the input.

 :~$ sudo ./program
 program_prompt> command1
 process has started
 program_prompt> command2
 process ended
 The output is foo bar
 program_prompt> ^C
 :~$
 :~$

I want to enter inputs into my fake terminal and continue to be able to enter inputs. From what I have gathered, I can pipe in strings into a command and sort of do this.

 echo "command1" | sudo ./program

This is the closest I have gotten to entering commands into my fake terminal. The fake terminal immediately ends after executing this command. I never get a chance to enter command2 and see the output. Im pushed back into the real terminal :~$

 :~$ echo "command1" | sudo ./program
 program_prompt> command1
 process has started
 program_prompt> :~$

I dont know if this is the proper path to do this. If I can do something different in php, js, or jquery to also accomplish please post a method.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)