I am trying to establish SSH connection to a remote server to execute some command. I require to take CLA in my final program, so I'm trying to execute from Command Prompt. A sample code is given
#include <stdio.h>
#define PATH_MAX 128
int main(void){
FILE *fp;
char path[PATH_MAX];
fp = popen("ssh user@HOST \"command\"", "r");
if (fp == NULL)
/* Handle error */;
while (fgets(path, PATH_MAX, fp) != NULL)
printf("%s", path);
fclose(fp);
return 0;
}
The code execute fine using DevC++ but when I execute same from Command prompt it does not execute giving following message "'ssh' is not recognized as an internal or external command, operable program or batch file." I tried both system("some command") and popen(). Both work fine in DevC but give same message when executed from Command Prompt. I'm having MinGW installed gcc version 8.2.0 (MinGW.org GCC-8.2.0-3)
SSH.exe
needs to be in the Windows PATH
. When the program is running, it might not be running under your profile.
It is possibly running under a system profile that does not have the same PATH
defined. You could have the program check and/or update the PATH
or have it run under your profile specifically.