Any way to know which operating system the client is connected from?

164 Views Asked by At

I am calling STRPCCMD command and passing it some parameters.

The command needs to work on linux and windows boxes.

Any way to find out which machine the user is connected from in order to build a proper command?

Currently I am issuing both and ignoring the errors.

3

There are 3 best solutions below

2
Charles On BEST ANSWER

Nope.

And this that's not long enough to count as an answer, let me point out that STRPCCMD is very limited.

Actually, I'm shocked that IBM included it in ACS.

1
Chris On

If you connect with the newest JDBC-Driver you can use the CURRENT CLIENT_ACCTNG Value to get this information.

0
M. A.  Wheadon On

I recently had this problem too (though I didn't find this question when searching for answers). I did solve it but not in an entirely satisfactory way.

The first thing I did was to have a setting in my application to indicate if the client was just using Windows, or they might use Windows or Linux. If just Windows only then no problem, if both then discern which at run time. I did try to use IBM APIs QDCRDEVD and QUSRJOBI but nothing there. I also asked a question of IBM but they didn't have an answer either.

In the end I executed this command:

strpccmd pccmd('waitfor /t 2 notthere') pause(*yes)

The command 'waitfor' is a Windows command that will wait, in this case, for 2 seconds. The 'notthere' is the name of a signal (which I don't want to be valid). On Linux this command returns immediately. On Windows it waits for 2 seconds. So, by timing the response I determine which OS we are running on. This is the C++ code I wrote to do this:

static OperatingSystems getHostOperatingSystem() {
  bool mixedClients = isMixedClients();  // get the setting
  if (!mixedClients) {
    return(windows);
  }

  strPco();  // runs the STRPCO command
  int ret = 0;
  time_t timeStart = time(NULL);
  ret = system(STRPCCMD_WAIT.c_str());
  if (ret != 0) {
    Qp0zLprintf("Warning: Wait command execution returned %d\n", ret);
  }
  time_t timeEnd = time(NULL);
  double secs = difftime(timeEnd, timeStart);
  if (secs < 2) {
    Qp0zLprintf("We think the 5250 session is running on Linux\n");
    return(linux);
  }
  Qp0zLprintf("We think the 5250 session is running on Windows\n");
  return(windows);
}

The downside to this method is that on Windows it pops up a blank CMD box for the 2 seconds. It disappears automatically but the user will see it. I guess this only needs to happen once per 5250 sign on but there is it. It was the best I could do. I also raised a change request with IBM so that we could discover the underlying OS from IBM i code.