LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   [Java] Can't execute system command on Windows 7 (http://www.linuxquestions.org/questions/programming-9/%5Bjava%5D-cant-execute-system-command-on-windows-7-a-919683/)

dwhitney67 12-20-2011 11:12 AM

[Java] Can't execute system command on Windows 7
 
I am currently maintaining a non-GUI Java application which requires the ability to pop-up a system dialog at a specified target (server).

For Linux, I can pop-up this dialog using something similar to the following command:
Code:

xmessage -display <host>:0.0 <message>
where <host> is the server name, and <message> is the message to present to the operator.

For Windows XP, something similar to the following is used:
Code:

net send <host> <message>
Now, for Windows 7, from what I understand, "net send" is no longer supported. Thus I have been attempting to use the "msg" command; something like:
Code:

msg /server:<host> <user> <message>
where I merely set <user> to an asterisk (shift-8). The command above works as expected from a command prompt, however when I attempt to execute it from a Java application, it does not work. Here's the code I'm using:
Code:

import java.io.*;

public class Popup
{
  public static void main(String[] args)
  {
      try
      {
        String[] app_args = { "msg", "*", "/server:localhost", "hello" };

        Process p = Runtime.getRuntime().exec(app_args);

        p.waitFor();
      }
      catch(IOException e1)
      {
        System.err.println(e1.toString());
      }
      catch(InterruptedException e2)
      {
        System.err.println(e2.toString());
      }
  }
}

This is the error I get:
Code:

java.io.IOException: Cannot run program "msg": CreateProcess error=2, The system cannot find the file specified
I've tried specifying the fully-qualified path to the command (C:\Windows\System32), however this does not work either. Can someone assist me with figuring this out? I do not have much experience with Windows.

dwhitney67 12-20-2011 08:01 PM

Well, I found a workaround to get the application to run successfully. I had to run the application with a 64-bit version of the JRE; if I use the 32-bit version, the app does not display the message dialog. The system is configured with the 64-bit version of Win7 Ultimate.

Anybody have any ideas why Windows has to suk more? Or is this a JRE problem?

sundialsvcs 12-22-2011 05:05 AM

Oh, I think that Windows has a truly unlimited capacity to "suk more" ... ;) ... :D

Seriously: as a matter of principle you need to be sure that the runtime engine you are using is recent, and well-matched to the vintage of host operating system that you are using. Although the purpose of any p-machine is to allow the p-code to be host independent, the p-machine implementation itself is decidedly not. Although I couldn't resist taking a gentle jab at Redmond, the truth of the matter is that it's not really Windows' fault. (Nor, for that matter, is it yours.)

SigTerm 12-22-2011 11:41 AM

Quote:

Originally Posted by dwhitney67 (Post 4554864)
Well, I found a workaround to get the application to run successfully. I had to run the application with a 64-bit version of the JRE; if I use the 32-bit version, the app does not display the message dialog. The system is configured with the 64-bit version of Win7 Ultimate.

Anybody have any ideas why Windows has to suk more? Or is this a JRE problem?

As far as I can tell, there seem to be some problem when calling CreateProcess from 32bit app on 64bit system. A wild guess (I don't have 64bit system and haven't dealt with that problem before) is that for 32bit app "filesystem redirection" is enabled, and there's no 32bit version of msg in system32 that is visible for 32bit app and is located %windir%\sysWOW64. You might want to read filesystem redirection article on MSDN>


All times are GMT -5. The time now is 12:13 AM.