Paul Agola

Greenhorn
+ Follow
since Jul 03, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Paul Agola

I am attempting to use Runtime.exec to launch a process from a Java program. The requirements state that i must suspend the parent process and wait until the child process has been closed and then return continue with the parent process. The parent process is a GUI and i launch the child process from a menu item. I have a specific utility class that is responsible for launching the process. Below is a sample of the code and where i think the problem is.



The problem is that is just keeps hanging and even when i terminate the sub child process it still hangs and the GUI is frozen. I know many people will recommend the java article about when runtime exec won't execute but as you can see from the code above i have created a StreamGobbler class which handles both the input and output streams of the child process so i do not understand why it keeps hanging?
4 years ago

Paul Clapham wrote:

Paul Agola wrote:i have read the article and i only understand upto page 3. I dont understand how i am supposed to handle both the input and the ouytput with different threads



Page 4 has an example of exactly that. Read the article and keep reading it (and trying simple code based on it) until you do understand it.




Thus, to circumvent the second pitfall -- hanging forever in Runtime.exec() -- if the program you launch produces output or expects input, ensure that you process the input and output streams.



my program produces output but it is displayed on the xterm so why should i process this output. it calls a csh script that cat information from a log to a file so why should i process it

Paul Clapham wrote:

Paul Agola wrote:i have read the article and i only understand upto page 3. I dont understand how i am supposed to handle both the input and the ouytput with different threads



Page 4 has an example of exactly that. Read the article and keep reading it (and trying simple code based on it) until you do understand it.



Knowing that this is going to the stderr stream, you can easily write a program to exhaust that stream before waiting for the process to exit.



i am already doing this is in my code and he says this is the solution to the hanging of runtime.exec(). Do you know what he means by "going to the srderr stream? i thought that stream is only for errors that occur when you are trying to execute the command. Right now there is no error and it brings up the xterm and displays the file as expected but it just hangs up

Paul Clapham wrote:

Paul Agola wrote:i am a novice at java threading and i do not understand what you mean



Read the article I posted the link to. You won't have to be a threading genius to understand it. Just read it.




i have read the article and i only understand upto page 3. I dont understand how i am supposed to handle both the input and the ouytput with different threads

William Brogden wrote:Hanging while exec-ing is frequently due to not consuming both the stdout and stderr streams.

You can not depend on consuming both unless you start a separate Thread to consume each one. Slight differences in program output can cause irregular behaviour.

Bill



Sir
i am a novice at java threading and i do not understand what you mean
have a java GUI that when a menu item is clicked it will use the runtime.exec method to execute a process and bring up a report. It does that just fine but then it suddenly freezes up and i cannot access anything for a while. I cannot even scroll through the report to analyse the data. The report is shown on an xterm and i am wondering why i cannot do anything after the report is created. 1. My java code that executes the csh script


When i comment out my error checking code everything works fine and the program doesn't freeze up. It has something to do with the inputsream reading an erro message. This is the portion of code that i comment out



it is somehow hanging up when this happens and i dont know why. Can somebody help because i definately need this error checking portion incase anything goes wrong. I have narrowed it down to the while loop. Everything else works normally but as soon as i put the while loop to read from the buffer it freezes up again. Somehow the subprocess is taking too long to temrinate. Here is the code that is not working


Essentially there are no errors in the script because it produces the report so the geterrorstream should be NULL causing the while loop to be ignored but it is not? It seems like it is reading something for a while(hence freezes up).

i have a java GUI that when a menu item is clicked it will use the runtime.exec method to execute a process and bring up a report. It does that just fine but then it suddenly freezes up and i cannot access anything for a while. I cannot even scroll through the report to analyse the data. The report is shown on an xterm and i am wondering why i cannot do anything after the report is created. 1. My java code that executes the csh script




When i comment out my error checking code everything works fine and the program doesn't freeze up. It has something to do with the inputsream reading an erro message. This is the portion of code that i comment out



it is somehow hanging up when this happens and i dont know why. Can somebody help because i definately need this error checking portion incase anything goes wrong. I have narrowed it down to the while loop. Everything else works normally but as soon as i put the while loop to read from the buffer it freezes up again. Somehow the subprocess is taking too long to temrinate. Here is the code that is not working


Essentially there are no errors in the script because it produces the report so the geterrorstream should be NULL causing the while loop to be ignored but it is not? It seems like it is reading something for a while(hence freezes up).


further reports when i bring up my xterm and just type

/bin/csh -c vobs/tools/Scritps/DataValidation/mysqlconnection.csh it seems to work so why wont it work using the java runtime.exec method?

everything seems to work fine from command promp and this above is the string that i am passing in so i dont udnerstadnw hy it doesnt work
5 years ago
I have a java class in which I call a runshellscript method that will execute a script. It worked well with mysql but I cannot seem to find out why it wont work well with psql. Here is an excerpt of my runshell method:





the problem is that when i put this behind a mouse clicked event it says command not found. Here is the code beuind the mous event



The weird thing is that when I go directly to the directory where the script resides and type ./mysqlconnection the script works. But when i just type mysqlconnection is says command not found. Somehow it is not recognizing my script name as a command?
5 years ago
i am trying to share variables between two different netbeans froms. One form which is themain form calls the other form like so




i need the UpdateData form to display the year1 variable in a textbox field like so




the problem my update form doesnt recognise this variable? I In simplicity how do i get a variable from one form and pass it to another form and ii am using netbeans?
5 years ago
new developments. I have added code to be able to
1.insert an empty row in the jtable and
2. delete an empty row in the jtable

as you can see this is not very practical here is the code used for each button. Myabe now i have shown that i am trying to actually code lol

code to add empty row


code to delete empty row



i know for the add i have to add some values but im not sure how to do it.
5 years ago
ok i am going to take it one step at a time. I figured to isnert rows the first thing i will have to do is insert a new vector in the tablemodel like so



where the new Object is the vecotr consisting of the column names that will be added. But when i press the button it is not doing anything. Im not limiting myself i just wantedot know wehre to start writing the code.
5 years ago

Paul Clapham wrote:Ah, I see. So in fact you haven't written a table model class. Then you will have to do that, I suppose. Or perhaps you could attach a TableModelListener to the table model and update the database based on the TableModelEvents you receive from it.

Although I am completely unfamiliar with Netbeans -- for all I know it might have a database-backed JTable as one of its choices.



im thinking the same thing. With the IDE i think i will be able to listen for events by altering the properties of the Jtable control. But as for the methods it already contains them and i am lost onto how to add rows from thejtable and have that propagate to the database
5 years ago

Paul Clapham wrote:You appear to know that it's the table model which will have to do this work, but still you didn't post the code for the table model.

Anyway. You would have to override the addRow() and insertRow() methods to handle inserts to the table, and you would have to override the setValueAt() method to handle updates to existing rows. And removeRow() to handle deletes.



logically i know i have to write code to perform these steps

1. add listener to jtable component
2. get row and column selected
3. Addrows and column selected to model
4. Add vector to the database via a select statement

but sinceim new to java swing (and java itself) and i created my gui with netbeans this is a bit hard for me to do
5 years ago

Paul Clapham wrote:You appear to know that it's the table model which will have to do this work, but still you didn't post the code for the table model.

Anyway. You would have to override the addRow() and insertRow() methods to handle inserts to the table, and you would have to override the setValueAt() method to handle updates to existing rows. And removeRow() to handle deletes.



you ask for the table model code but i stated that this has been created by netbeans? what exact code would you be reffereing to. I used netbeans and imported the default table model package so i dont udnerstand what code you need me to post? I have never developed java swing components from scratch and i am using netbeans which of course isnt recommended but that is what has been chosen. These methods that i have to override are they part of the table model class and if so how do i do that?
5 years ago