Qt Creator stdin for command line with Deploy to Remote Linux Host

天涯浪子 提交于 2019-12-05 18:45:14
PhilBot

I found out that there is no way to provide stdin to an app launched by qt creator from within the IDE.

I did try a few things and it looks like a named pipe works just fine. Luckily it’s included with Busybox so it’s on my board.

To use it you launch the app remotely from Qt Creator using the ‘Alternate executable on device’ option under ‘run settings’ and pipe the last line of the named pipe to your c++ program expecting stdin. So your ‘Alternate executable on device looks like:

cd /home/test; tail -f mypipe | ./test3 –qws

‘test3’ is my program and /home/testis the location of the executable.

Then open up 1 extra ubuntu terminal and SSH to the board. Now create a named pipe called ‘mypipe’:

mkfifo mypipe

And when your program expecting stdin launches and waits for input, you can echo the input from that other terminal into the named pipe and your program will take it as stdin:

echo ‘2’ > mypipe

There are more options in Debug > Start Debug submenu. And there's one that you need: Attach to Running Debug Server. It does open this neat little window:

As you can see, there's a lot of parameters, even "Run in terminal" option, but it doesn't work on my machine for some reason. Don't forget to properly set your local path to executable binary and kit device settings. I would also recommend you to bind hotkey for AttachToRemoteServer command in Environment > Keyboard settings.

After that the only thing you need to do is to run gdbserver on your remote device:

gdbserver :<port> <executable>

Running process does have a proper stdin and stdout streams and you can interact with your application in terminal via SSH session.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!