I have a simple function that I wish to perform in a .NET program. I am currently working in C# with .NET version 1.1, but any .NET language help would be useful. I want to be able to send a remote command to a UNIX or VxWorks computer form a Windows PC. From VxWorks to UNIX this would require only a single line of code - a call to the function "rcmd", as in this example that gets the time on the UNIX box:
int getHostDate
(
char *unixHost,
char *userId,
char *userPassword,
char *returnDate,
char returnErrorMsg[30],
int outFormat /* 0 = default 1 = numeric */
)
{
int rshdSockFd;
char userName[20];
char dateCmdStr[30];
char buf [BUFSIZE];
int nRead;
if (unixHost == NULL)
{
sprintf (returnErrorMsg,"Invalid host name\0");
return (ERROR);
}
if (outFormat == 1) {
sprintf(dateCmdStr,
"date '+%%Y %%m %%d %%w %%H %%M %%S'");
}
else {
sprintf(dateCmdStr,"date");
}
if (([b]rshdSockFd = rcmd (unixHost, RSH_PORT, userId, userPassword, dateCmdStr, 0)[/b]) == ERROR)
{
sprintf (returnErrorMsg,"Remote Command Failed\0");
return (ERROR);
}
if ((nRead = read(rshdSockFd, buf, BUFSIZE)) == ERROR)
{
sprintf (returnErrorMsg,"Read from Socket Failed\0");
close (rshdSockFd);
return (ERROR);
}
else
{
buf [nRead - 1] = '\0';
sprintf (returnDate,"%s", buf);
close (rshdSockFd);
return(nRead);
}
}
I have searched the web to see what others do, and the usual answer is to write a new server on the UNIX side. This seems like severe overkill, as the ability to receive remote commands already exists in UNIX, as evidenced by the working code above. This action can be accomplished manually by simply bringing up a telnet window and typing in the appropriate commands. Is it really so difficult to do in .NET that it is better to change the UNIX server itself (a suggestion I wouldn't even think of making)?
Thanks,
Dale