Brian McGuinness

+ Follow
since Mar 06, 2014
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Brian McGuinness

Ok. For now I will clean up the pipe connector class as you have suggested.

I will have to experiment with extending the Process class and see what happens.

I find the leading underscores useful for identifying member names since I don't have to search all over the code to find where a variable was defined; I know right away when it's a member, which is defined at the top of the class.

Thanks for your help.
5 years ago
The reason it seems kludgey is that Java has the capabilities necessary to make pipes work, so they should provide a simpler way of creating the pipe connections that I need. For example, providing methods in ProcessBuilder to redirect streams, rather than just files, would solve the problem. It shouldn't be necessary to resort to workarounds.

In any event, I added code to my pipe connector class to close the I/O streams after copying was finished, and now my pipes seem to work properly. Apparently, the output wasn't being flushed, and that kept the threads from terminating. So now I have:

Thanks very much for your suggestions and feedback.
5 years ago
I tried this:

When I ran it, it just sat there for a moment and I got no output.

Meanwhile, I created a pipe connector for my shell:

I tried setting up a pipeline with this, starting with the last process and moving backward to the first, so each process would block while waiting for input from the previous process:


When I tried entering pipeline commands and executing them, the first process completed but the others froze, according to the diagnostic messages from my program. I used

to wait for the pipeline to complete. For the line "ls -l | sort" I got:

and I got no output from the pipeline. When I tried "cat ../cantrips.txt | sort" to display a decent sized text file, I got

and again there was no output, but this time when I exited the shell (my Java program) the sorted lines from my text file displayed on the screen. So the file actually had passed through the pipeline to sort and been sorted, but it then got hung up somehow and didn't display until the shell exited.
5 years ago
Ok. This seems like a rather kludgey approach. I was thinking that there had to be a better way to do this, but it was probably buried deep in the documentation somewhere. But apparently that is not the case. I will write a simple pipe manager and use that in a thread to connect each pair of processes.

Thanks for the suggestion.
5 years ago
Thanks, but that reference, like other articles I have seen, just indicates how to establish pipes between two threads of a Java program. I want to set up a pipeline between separate programs (I am experimenting with writing a shell in Java), so I need to use ProcessBuilder, not Runnable. The problem is that ProcessBuilder only provides methods to redirect to files, and Process only returns InputStreams and OutputStreams, not PipedInputStreams and PipedOutputStreams, which you could connect. If ProcessBuilder was designed properly, it would support redirection to streams, so you could redirect to file streams, string streams, piped streams, or anything else you wanted rather than just to files. I don't see how to get around these limitations and establish the connections that I want between the processes. There should be a way to do this, but it's hard to find.
5 years ago
I want to create a pipeline where I create processes with ProcessBuilder and then pipe the standard output from each process into the standard input of the next one. I see that by default, ProcessBuilder directs standard input, standard output, and standard error to pipes, but the ProcessBuilder's redirection methods only let me redirect I/O to *files*, there are no methods provided to redirect I/O to PipedInputStreams or PipedOutputStreams. On the other hand, a Process can return its I/O streams, but only as InputStreams or OutputStreams, not PipedInputStreams or PipedOutputStreams. And plain InputStreams and OutputStreams don't provide a connect() method to connect them. So how do you connect these?

The Java process library seems to be very poorly designed. I have already discovered that ProcessBuilder.inheritIO() doesn't work properly if the I/O streams of the parent process have been redirected. Now I have the above frustration with pipelines.
5 years ago
Ok, I think I have this sorted out now. This seems to work pretty well:

6 years ago
I find JTable very irksome to use, since I almost always have to laboriously set the column widths to avoid having fields truncated, and it is very difficult to perform simple operations that people often find desirable, such as striping rows. So I decided to create my own table class that was easier to use rather than wasting any more time fighting with JTable. The basic idea is to use a gridbag layout to create a matrix of JLabels. This seems to work pretty well for the most part, but the problem is that when I set the fill to GridBagConstraints.BOTH I can't get the text in each data cell to be left justified; it keeps coming out centered. I would appreciate any help with this. My simplified table class is:

where GridBagPanel is a simple class that takes care of dealing with the GridBagConstraints (initializing fields to reasonable defaults) and lets me add components simply by invoking addComponent (x, y, width, height, component).

Thanks for the help.
6 years ago
Ok, thanks for the pointers. I now have the progress bar working ok. What I did was to create a new interface to ensure that the class performing the lengthy file processing process would provide all of the query functions required by the ProgressBar to update its display:

I then added these functions to my file processing class, along with run().

Then I modified my ProgressBar class so that the Trackable class was one of the arguments to the constructor. The ProgressBar could then create a new thread for the Trackable class and start it. (I didn't want the user to have to click a Start button to start the process, since he had already selected a menu item and selected a directory from a FileChooser.)
After the main program launches the ProgressBar, control is immediately returned to it and the user can perform other operations, which is what I want. But now I have to figure out how to determine when the file processing class has finished executing so I can check its status and display an appropriate message, e.g. "installation aborted by user", "installation aborted due to file I/O error", "installation completed successfully", or whatever.

6 years ago
I wish to display a progress bar during a lengthy file translation process. When I created a ProgressBar class to do this and tested it with a short test program, it seemed to work fine. But when I add my ProgressBar class to a package containing various other classes, put that package in a jar file, and then execute the class using the progress bar from a menu in my main program, the frame of the progress bar shows up with the appropriate caption but the JLabel, JProgressBar, and JButton are not displayed. I have gone over my code numerous times and checked that the ProgressBar class constructor is getting the proper arguments, but I can't find anything wrong. I am completely mystified by this.


// The progress bar works ok with this test program:

Any help would be appreciated.

I have also been wondering whether I need a separate instance of the border for each panel, or whether I can just create one instance and use it for all three panels.

--- Brian
6 years ago