You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Its not immediately visible to the end user that exit code was 1, to the end user, it simply appears that the command was sent successfully. Here is a screen grab of the behavior I'm observing
`john@wa1okb-r:~$ RemoteCommand 7624 page 0129939 "This is a test message"
Command sent: "page 0129939 This is a test message" to port: 7624
john@wa1okb-r:~$ echo $?
1
`
As you can see, the end user only gets the Command sent: message... It appears in all respects that it sent successfully... yet echo $? shows the return code from the command was 1, indicating it was NOT successful.... and no indication as to why it wasn't successful.
Propose changing the code such that it doesn't print the Command Sent message until after its actually verified that the command was sent successfully, and that the return code is 0
It appears that the "Command sent: " line is printed after the command is successfully written to the socket with the socket.write method. The return code of 1, however, is set later in the CRemoteCommand::send method if there’s an error or no data is read from the socket after sending the command.
I apologize, as I don't know C++ well enough to confidently submit a code change via github... but from what I do understand, i would suggest moving the ::fprintf(stdout, "Command sent: \"%s\" to port: %u\n", command.c_str(), m_port); to the CRemoteCommand::send method, so that it only prints once we know its actually been successful. something like this:
`int CRemoteCommand::send(const std::string& command)
{
sockaddr_storage addr;
unsigned int addrLen;
char buffer[BUFFER_LENGTH];
int retStatus = 0;
if (CUDPSocket::lookup("127.0.0.1", m_port, addr, addrLen) != 0) {
::fprintf(stderr, "Unable to resolve the address of the host\n");
return 1;
}
CUDPSocket socket(0U);
bool ret = socket.open(addr);
if (!ret)
return 1;
ret = socket.write((unsigned char*)command.c_str(), command.length(), addr, addrLen);
if (!ret) {
socket.close();
return 1;
}
std::this_thread::sleep_for(std::chrono::milliseconds(50));
int len = socket.read((unsigned char*)buffer, BUFFER_LENGTH, addr, addrLen);
if (len > 0) {
buffer[len] = '\0';
::fprintf(stdout, "Command sent: \"%s\" to port: %u\n", command.c_str(), m_port);
::fprintf(stdout, "%s\n", buffer);
}
else
{
retStatus = 1;
}
socket.close();
return retStatus;
}
`
The text was updated successfully, but these errors were encountered:
Its not immediately visible to the end user that exit code was 1, to the end user, it simply appears that the command was sent successfully. Here is a screen grab of the behavior I'm observing
`john@wa1okb-r:~$ RemoteCommand 7624 page 0129939 "This is a test message"
Command sent: "page 0129939 This is a test message" to port: 7624
john@wa1okb-r:~$ echo $?
1
`
As you can see, the end user only gets the Command sent: message... It appears in all respects that it sent successfully... yet echo $? shows the return code from the command was 1, indicating it was NOT successful.... and no indication as to why it wasn't successful.
Propose changing the code such that it doesn't print the Command Sent message until after its actually verified that the command was sent successfully, and that the return code is 0
It appears that the "Command sent: " line is printed after the command is successfully written to the socket with the socket.write method. The return code of 1, however, is set later in the CRemoteCommand::send method if there’s an error or no data is read from the socket after sending the command.
I apologize, as I don't know C++ well enough to confidently submit a code change via github... but from what I do understand, i would suggest moving the
::fprintf(stdout, "Command sent: \"%s\" to port: %u\n", command.c_str(), m_port);
to the CRemoteCommand::send method, so that it only prints once we know its actually been successful. something like this:`int CRemoteCommand::send(const std::string& command)
{
sockaddr_storage addr;
unsigned int addrLen;
char buffer[BUFFER_LENGTH];
int retStatus = 0;
}
`
The text was updated successfully, but these errors were encountered: