LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 12-20-2011, 12:12 PM   #1
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,523

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
[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.

Last edited by dwhitney67; 12-20-2011 at 09:01 PM.
 
Old 12-20-2011, 09:01 PM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,523

Original Poster
Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
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?

Last edited by dwhitney67; 12-20-2011 at 09:29 PM.
 
Old 12-22-2011, 06:05 AM   #3
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,455

Rep: Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172
Oh, I think that Windows has a truly unlimited capacity to "suk more" ... ...

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.)

Last edited by sundialsvcs; 12-22-2011 at 06:08 AM.
 
Old 12-22-2011, 12:41 PM   #4
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by dwhitney67 View Post
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>
 
  


Reply

Tags
java, windows 7


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing df -k command from java is not working for multiple execute riyas_ppt Programming 1 01-13-2012 11:20 AM
perl script system() only execute one command knockout_artist Programming 4 11-11-2008 11:57 AM
Execute a linux command using a java program tvalenzuela Programming 2 10-07-2005 12:59 PM
execute system command from c alaios Programming 2 07-19-2005 08:45 AM
execute system command in c alaios Programming 3 07-13-2005 06:26 AM


All times are GMT -5. The time now is 05:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration