I am trying to execute some powershell scripts from Linux using a C program automatically. I am using libexpect to send the commands to Windows and get the file descriptor of the powershell terminal and writing to it to run powershell scripts/commands. It works fine. But my requirement is that I want to be able to read the output of the powershell script from my C program.
C program looks like this:
fd = exp_spawnl( "sh", "sh", "-c", "telent -l username machine", (char*)0);
exp_expectl( fd, exp_glob, "password: ", 1, exp_end);
write(fd, "password\r", NUM_BYTES);
exp_expectl( fd, exp_glob, ".*>", 1, exp_end);
write(fd, "powershell \path\script.ps1\r", NUM_BYTES);
As it's above, it's not possible to get the stdout/stderr of powershell script.ps1 that's being executed on windows.
The whole setup of linux-windows-powershell-linux is in a local network. Hence, I am not too worried about using telnet at the moment. But I am open to any solutions (ssh or not) that helps achieve my goal.
I am open to not using libexpect as well if there are alternative options. Basically I can change anything in this approach. I am using it because I am not aware of any other way to send in username/password and commands to the remote shell as done expect (libexpect).
I am open to suggestions on writing a expect/bash script on linux OR some on-the-fly powershell script on windows as long as my primary objective is met i.e. execute powershell scripts/commands automatically and get stdout and stderr of them and their exit status $?. Note that I don't need the file pointers themselves, I am quite happy if I can get the values in a char[] (like OUTPUT=$(ls) in bash).