aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes trying to run a c-shell script from a mouse pressed event in netbeans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "trying to run a c-shell script from a mouse pressed event in netbeans" Watch "trying to run a c-shell script from a mouse pressed event in netbeans" New topic
Author

trying to run a c-shell script from a mouse pressed event in netbeans

Paul Agola
Greenhorn

Joined: Jul 03, 2012
Posts: 23
have a form that has a menu and sub menu's. I want the user to be able to click on a menu item and have the script run itself. So i created java utility class and added it to the project. Here is the code of what my class looks like





In my mousepressed event handler i create an isntance of the class and call the method, passing in the command name as a string like so




The problem is it does nothing. It just runs but doesnt do anything. to give a better view of what my sript looks like i have posted it below



As the script variables are part of my env variables so i dont think i need to pass those into my runshellscript class to get it working

As you can see, there is a sql script within this c-shell script and it looks like so



and within this script it finally executes a sql statement and returns the results to a txt file



The problem is nothing happens? what am i missing. Maybe my utility class needs the whole path specified as the input string? any ideas?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

You should read When Runtime.exec() won't. Right now you are calling waitFor() before reading all the data.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Agola
Greenhorn

Joined: Jul 03, 2012
Posts: 23
i have read the article and i dont quite understand why my code is not working. I am new to java so would you please assist me more in explaining how i am not reading all the data in?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Welcome to the Ranch

I think you ought to go through the article Rob quoted very slowly and carefully. Also forget about Swing. Run that Process from a command line application, and keep going until you get it working properly. Then you can incorporate it in a Swing application.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

What Rob said was pretty clear.
Rob Spoor wrote:Right now you are calling waitFor() before reading all the data.


Change the order of your code lines so that you read the data before calling waitFor().


luck, db
There are no new questions, but there may be new answers.
Paul Agola
Greenhorn

Joined: Jul 03, 2012
Posts: 23
ok so i actually go it to show an error this time. It failed to oopen my iers .sql file i wonder why. I have permissions set to rwxrwx for this file . If it could open the other two why is it failing ont his one?

[code=java][run:
<ERROR
ERROR at line 12: Failed to open file 'IERSParameters.sql', error: 2
null
Process exitValue:1/code]
Paul Agola
Greenhorn

Joined: Jul 03, 2012
Posts: 23
Darryl Burke wrote:What Rob said was pretty clear.
Rob Spoor wrote:Right now you are calling waitFor() before reading all the data.


Change the order of your code lines so that you read the data before calling waitFor().


i wrote the program without swing and got it to run fine. Then i incorporated it into my swing menu item event and it failed to open the .sql file

>
Paul Agola
Greenhorn

Joined: Jul 03, 2012
Posts: 23
problem solved. Apparently that was a path issue. I had to specify the full path of where my IERParameters.sql was and this solved the issue. My last question is that do we have to give the absolute path to where the .csh script is? i mean i have thousands of scripts and they reside in the same folder but it seems i have to give the whole path to the exec function?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: trying to run a c-shell script from a mouse pressed event in netbeans