Announcement Announcement Module
Collapse
No announcement yet.
Run a .exe file using Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Run a .exe file using Spring

    Hi,
    i have a .exe, which i need to execute from my java code(using spring frame work).

    I have two cases:
    1) .exe file is in local system.
    2) .exe file is in remote

    Are there any API's available in spring framework to do this.

    Thanks for any help.

    Ramya.

  • #2
    I would do a general search on the net for running executing exe's from Java.
    Last edited by karldmoore; Aug 29th, 2007, 11:53 AM.

    Comment


    • #3
      Hi,
      Thanks for that, is there any package provided by the spring for that.
      i Need to call the exe file which is located in the remote system.
      I am using java's Runtime

      Runtime rt = Runtime.getRuntime();
      Process proc = rt.exec("C:\\software\\npp.4.0.2.Installer.exe");
      int exitVal = proc.exitValue();
      System.out.println("Process exitValue: " + exitVal);


      Is there any thing specific that i have to do to execute a remote file.
      I heard about socket programming, to how extent it will be useful to me.

      Thanks for any help.

      Ramya.

      Comment


      • #4
        This isn't really a Spring issue but...

        What exactly do you mean by executing a remote file? There's no inherent way to execute a file on a remote system, but there are a few options...

        a) Map it to the local computer so that it appears to be a local file. This will run on your system but be stored remotely.

        b) Run a server on the remote system that calls Runtime.exec() there. You can do this using the ServerSocket interface or any other language, but it's kind of hacky.

        c) Run a remote service using RMI that does the same. Slightly less hacky, but requires Java and some additional constraints.

        d) Run a service through some other server container, using some form of CGI or something, possibly calling it via JNDI. I suppose if you really wanted to, you could develop a Spring servlet on the remote computer and have your local servlet post HTTP to it...

        e) Make it a web service and call it with SOAP. This is probably the most elegant and buzzword-compliant option.

        Without knowing more about the situation, I really can't suggest anything else. It depends on how much control you have over the remote system, how many resources you want to occupy, how much effort you want to put into it and how strong/secure/etc you want it to be.

        Comment


        • #5
          I'm with the other poster here, I'm confused about what you are actually trying to do. Executing remote files using sockets? Any chance you can explain a little more about what you're trying to do?
          Last edited by karldmoore; Aug 29th, 2007, 11:52 AM.

          Comment


          • #6
            Hi,
            sorry for the late reply.
            What i am trying to say is, there is an executable file say for example addmember.exe(adds a member to a database and some other stuff...) in a remote system. From my java code i need to invoke the exe file so that it is executed in the remote system and adds a member to a database.

            For example:
            Process p = Runtime.getRuntime().exec("C:\member\addmember.exe ");

            I can use java api like this to run the exe file.Still i need to find out how to run if this file is there on a remote system.

            Is there any spring specific ways of doing this, with out using the usual java API.

            Thanks for any help.

            Thanks,
            Ramya.
            Last edited by ramyareddy; Jun 26th, 2007, 05:20 AM.

            Comment


            • #7
              Originally posted by ramyareddy View Post
              Hi,
              sorry for the late reply.
              What i am trying to say is, there is an executable file say for example addmember.exe(adds a member to a database and some other stuff...) in a remote system. From my java code i need to invoke the exe file so that it is executed in the remote system and adds a member to a database.

              For example:
              Process p = Runtime.getRuntime().exec("C:\member\addmember.exe ");

              I can use java api like this to run the exe file.Still i need to find out how to run if this file is there on a remote system.

              Is there any spring specific ways of doing this, with out using the usual java API.

              Thanks for any help.

              Thanks,
              Ramya.
              No. This is not in the Spring remit.

              Comment


              • #8
                The remoting side of this is fine, there are lots of non-Spring and Spring ways of doing this. As for the actual call what's wrong with what you have?
                http://www.springframework.org/docs/.../remoting.html
                Last edited by karldmoore; Aug 29th, 2007, 11:52 AM.

                Comment


                • #9
                  addmember.exe requires two input parameters, which i used to pass through command prompt.With java Runtime(Process p = Runtime.getRuntime().exec("C:\member\addmember.exe ) i didn't have a chance to pass input parameters to the exe.

                  Is there any other way to pass parameters to the exe.

                  Thanks,
                  Ramya.

                  Comment


                  • #10
                    Would you like first look into the Javadoc for Runtime class, and only then ask questions?

                    This class contains a horde of different versions of the exec() method which allow for passing parameters, specifying environment variables and working directory.

                    For example
                    Process exec(String[] cmdarray)
                    Executes the specified command and arguments in a separate process.


                    Regards,

                    Oleksandr
                    Originally posted by ramyareddy View Post
                    addmember.exe requires two input parameters, which i used to pass through command prompt.With java Runtime(Process p = Runtime.getRuntime().exec("C:\member\addmember.exe ) i didn't have a chance to pass input parameters to the exe.

                    Is there any other way to pass parameters to the exe.

                    Thanks,
                    Ramya.

                    Comment


                    • #11
                      Originally posted by al0 View Post
                      Would you like first look into the Javadoc for Runtime class, and only then ask questions?
                      Indeed, this really is a Spring forum and the reference manuals and JavaDoc should be your first point of call.
                      Last edited by karldmoore; Aug 29th, 2007, 11:52 AM.

                      Comment


                      • #12
                        Originally posted by karldmoore View Post
                        Indeed, this really is a Spring forum and the reference manuals and JavaDoc should be your first point of call.
                        Especially for a standard Java SDK functionality that is not related to Spring.

                        Comment


                        • #13
                          Originally posted by al0 View Post
                          Especially for a standard Java SDK functionality that is not related to Spring.
                          Touche .
                          Last edited by karldmoore; Aug 29th, 2007, 11:52 AM.

                          Comment


                          • #14
                            i'll just share this since i haven't used it for so long. I read a good article and adapted this from it. Any questions just ask. The stdout & stderr streams are actually important to process, you can't just ignore them. Wire it as a spring bean and adapt as needed.

                            This was the article http://www.javaworld.com/javaworld/j...229-traps.html

                            Code:
                            public class ProcessForker  {
                            
                            
                            	protected static final Log LOG = LogFactory.getLog(ProcessForker.class);
                            
                            
                            	private class StreamGobbler extends Thread {
                            		private InputStream inputStream;
                            		private boolean verbose;
                            
                            		public StreamGobbler(InputStream inputStream, boolean verbose) {
                            			super();
                            			this.inputStream = inputStream;
                            			this.verbose = verbose;
                            		}
                            
                            		@Override
                            		public void run() {
                            			try {
                            				BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
                            				String line = br.readLine();
                            				while (line != null) {
                            					if (verbose)  {
                            						LOG.info(line);  // should probably store the stream if you need to parse output.
                            					}
                            					line = br.readLine();
                            				}
                            			} catch (IOException e) {
                            				LOG.error(e.getMessage(), e);
                            			} finally  {
                            				br.close();
                            			}
                            
                            		}
                            	}
                            
                            
                            	public int fork(String cmd, boolean verbose) {
                            		Process proc;
                            		int returnCode = -1;
                            		try {
                            			LOG.info("Forking process: " + cmd);
                            			proc = Runtime.getRuntime().exec(cmd);
                            
                                        StreamGobbler stdout = new StreamGobbler(proc.getInputStream(), verbose);
                                        StreamGobbler stderr = new StreamGobbler(proc.getErrorStream(), verbose);
                                        stdout.start();
                                        stderr.start();
                            
                            			LOG.info("Waiting for process.");
                                        returnCode = proc.waitFor();
                            		} catch (Exception e) {
                            			LOG.error(e.getMessage(), e);
                            		}
                            		return returnCode;
                            	}
                            }
                            Last edited by lloyd.mcclendon; Jun 27th, 2007, 09:27 PM.

                            Comment


                            • #15
                              Thanks Every Body.

                              Comment

                              Working...
                              X