File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes run exe in client sid Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "run exe in client sid" Watch "run exe in client sid" New topic
Author

run exe in client sid

raktim banerjee
Greenhorn

Joined: Feb 13, 2011
Posts: 18
Hello sir!

I had been trying to run executable file on the client side using jsp and servlet. The following code for running notepad.exe is working properly.


But i wrote this for running my own exe. There is no error in the error console of browser. But there is no expected output.



I am new in this field. Please help me regarding this matter.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Can't be done. Servlet code runs on the server. If you want such behaviour (and you want to use Java) you will need a signed Applet running the in the client browser.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

Servlets and JSP run on the server, not the client. So you cannot cause a client-side program to run. Imagine the security nightmare if you could!

If you need to run something on the client, you'll need to use an Applet or Java Web Start.

[Edit: Paul beat me to it]


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
raktim banerjee
Greenhorn

Joined: Feb 13, 2011
Posts: 18
Sir! I want to know both about runing exe in server side and client cide. I understand in case of server side i have to use servlet, and for client side applet.
In case of running exe using servlet, the code for running notepad.exe is working but the code for running my own exe is not working. what is the cause?

And how to run exe in client side using applet, please suggest me something.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


In case of running exe using servlet, the code for running notepad.exe is working but the code for running my own exe is not working. what is the cause?

What do the logs say?


And how to run exe in client side using applet, please suggest me something.[

The code will be very similar, but the Applet will need to be signed. See this.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

For executing with Runtime this article is a must read: When Runtime.exec() won't


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
raktim banerjee
Greenhorn

Joined: Feb 13, 2011
Posts: 18
here is nothing in logs. No error report.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
but the code for running my own exe is not working.



I would bet that your exe makes use of std out and/or std err output streams. Read the article Wouter pointed to.

Since notepad uses a window and does not use std out or std err, it does not hit this problem.

Bill


Java Resources at www.wbrogden.com
parampreet sethi
Greenhorn

Joined: Aug 03, 2009
Posts: 27

just a quick question here,

Since notepad uses a window and does not use std out or std err, it does not hit this problem.


Does it mean that any program which uses a window (basically window application) can be run on client side through servlet?


Param
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

parampreet sethi wrote:Does it mean that any program which uses a window (basically window application) can be run on client side through servlet?

No. It's already been pointed out that servlets cannot cause client-side programs to execute.
raktim banerjee
Greenhorn

Joined: Feb 13, 2011
Posts: 18
I would bet that your exe makes use of std out and/or std err output streams. Read the article Wouter pointed to.


Sir, with respect,

I am not using any std out or std err in my exe, which i want to run using servlet in the server side. The functionality of the exe is: It reads a string from a .txt file and watermark(invisible) in a picture. The output is a .m file. I made this exe using MATLAB compilor (mcc).

The exe, which i want to run using applet in the client side, takes input a .m file, extract the watermark and write it back in a .txt file.


William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
With respect eh? Well us aged Java gurus can always use a little respect.

Are you absolutely there is never any output to std out or std err? What do you with exceptions for example? If you don't catch and log them the JVM will try to write to std err.

Bill
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
Whoops I just reread the thread and see the .exe is a C program but the same question applies. The C runtime will write to std err if it gets an error - for example what happens if the file is not found?

Bill
raktim banerjee
Greenhorn

Joined: Feb 13, 2011
Posts: 18
I did not handle the exceptions in the MATLAB code before making exes. But the exes are working well when i am executing these manually. I checked that exec() is not working with any DOS based executable file, but it is working well with windos executable files. Is there any problem?
raktim banerjee
Greenhorn

Joined: Feb 13, 2011
Posts: 18
Whoops I just reread the thread and see the .exe is a C program but the same question applies. The C runtime will write to std err if it gets an error - for example what happens if the file is not found?


The servlet or applet code will check if the file exists or if there is another exceptions. Then it will call those exes.

Now is there any way?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
I repeat the suggestion - read the article Wouter suggested and follow the advice for consuming and displaying the std out and std err streams to find out why the exec is not working.

You might also want to read the java.lang.Process documentation about handling those streams.

Can you get a look at the executing processes on the server side when trying to run your .exe? In windows this would be via the Windows Task manager - if it shows your encryption.exe as just sitting there with no execution time, that should give you a hint.

Bill
raktim banerjee
Greenhorn

Joined: Feb 13, 2011
Posts: 18
At last i have done it. Many time I run the code. As encryption.exe and decryption.exe do not use any std output and lifetime is very sort, I was confused about the execution of these two exes. I expected the output in the same directory where the exe is. But i found the output in:



I wrote this:




This code worked.
That link helped me a lot. Also learned so many things about exec(). Now i will try to use the same code in applet for client side.

Thank you very much Sir William Brogden, Sir Paul Sturrock, Sir Paul Sturrock and Sir Wouter Oet.

With respect eh? Well us aged Java gurus can always use a little respect.


Want to say something to William Brogden,
The word "guru" is a Bengali word, Derived from Sanskrit "gurudev", means lord. We often use this word in our mother tongue.
Thanks a lot.
 
jQuery in Action, 2nd edition
 
subject: run exe in client sid
 
Similar Threads
running another application from java
run exe from servlet
Run mozilla or konqueror from java application
run exe
accessing java files within folders