Here is the part of code I have written to stuff 0 to a screen session open in one of my Ubuntu terminal tabs.
char command[60];
strcpy( command, "screen -S 8305.pts-1.MYUb -X stuff $'0'" );
system(command);
It gets compiled fine with only a warning like
ignoring return value of ‘system’,
But when it comes to running I get the message shown below:
No screen session found.
I have tried system() with other shell commands and it works perfectly fine. The command for screen also works fine when you run it in a terminal session not in c code.
I think the problem is you are using
-S
which creates a new named screen, and-X
which submits a command to an already running screen session.You either want:
OR
FYI -- I'm not sure what
stuff $0
is suppose to be, and in the context of the code you supplied is not going to work -- but I believe that a different problem then the one you reported.From
man(1)
pageAnd
Most probably you are running the command as a different user than the user that owns the screen. For example running the binary as sudo.
You can run
ps aux
to find the user under which your binary is running as.To make the system command work you should run it as the user who owns the screen.