I have a Qt application in C++ that runs on a Windows host and has to execute some commands via SSH in a Linux machine.
I tried everything that came to my mind but without a single success:
QProcess(), using bothssh <user>@<address> "command"andcmd /c "ssh <user>@<address> \"command\""did nothing,powershellsame story.- Same story using the
system(). - I tried both previous solutions with
runas /user:Administratorbut, again, nothing changed. - I embedded the SSH command in a bat file and tried with previous solutions. Same story.
In general, when using directly ssh I don't get any output and it doesn't run; when I prepend cmd /c (or powershell) I get:
ssh is not recognized as an internal or external command, operable program or batch file
I know that I could use libssh or libssh2 but it's been asked me to try to avoid them, so I'll use them only if there's no other options.
Some snippet that I tried using:
QProcess:QProcess* proc = new QProcess(); proc->start("ssh", {"<user>@<address>", "\"<command>\""}); proc->waitForFinished(); QString str = proc->readAll(); std::cout << "out: "+ QString::number(proc->exitCode()) + " -- " + str;- same as before but with full ssh.exe path
- same but with
proc->start("cmd", {"/c", "ssh", "<user>@<address>", "\"<command>\""}); system():
here I tried with all kind ofint ret = system("cmd /c \"ssh -t <user>@<address> \\\"<command>\\\"\""); std::cout()<<"ret: " + QString::number(ret));\escape possible.
EDIT:
Ok, I might have found something.. Basically when I launch the command from my application, the OpenSSH folder containing ssh.exe is "missing". If I dir in c:\Windows\System32, I see everything except for the OpenSSH folder. If I run the same thing from CMD, the folder is present and contains ssh.exe
Do you have any ideas on how to access the folder with my application?