This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 21775
103
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should read When Runtime.exec() won't. Right now you are calling waitFor() before reading all the data.
 
Paul Agola
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Marshal
Posts: 65089
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
Paul Agola
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!