I have a PHP script that goes through a lot of complication and, in the end, produces a command for the user to run. Right now, it prints the command and then quits. The user has to copy the command and paste it to run it. Because the PHP command is being run on the command line, it would be easier for the user if the PHP script was able to place the command on the command line. The user can just press enter. (Yes - it is a requirement that a human runs the command or I'd just execute the command from inside the script.)
I have tried using xclip to copy the command to the clipboard. It hangs. I've used exec and system to run it. The command to be run is in $command and I used:
exec("echo \"$command\" | xclip");
With both exec and system, it hangs until I ctrl-C and there's nothing in the clipboard.
UPDATE I found that if I pipe xclip to /dev/null in the command, it does not hang. I can then add it to the user's clipboard and he/she can run it using ctrl+shift+v
exec("echo \"$command\" | xclip -sel clip -i > /dev/null");
I've tried wrapping the whole thing in complicated scripts on the command line, tailing off the last line of output, and trying to paste that into the command line. I can get it to print the command, but not on the command line. It always prints the command and then the command line comes up below it.
I am using BASH for the command line. So, any solution must work in the bash shell - assuming that there is a solution.