0
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.
Can't your PHP script just prompt the user "To execute this {command} please press enter", wait for an enter key, then actually execute the command? – DavidPostill – 2016-01-07T20:16:47.393
@DavidPostill That was my suggestion. It didn't fly with the brass that are (ignorantly) making the decisions. I said that I would see if it is possible to do what they want. My next plan of action is to write a fake bash shell inside the PHP so it looks like you are running everything in bash - but then I will risk running the command inside itself over and over and over.... – kainaw – 2016-01-07T20:21:15.557
It's tough when manglement sucks ;) – DavidPostill – 2016-01-07T20:39:05.610
You can use "-loops 1" instead of ">/dev/null". – Ayell – 2017-12-24T14:15:53.780