Java - execute a system command pipeline (pipe)

In earlier articles I've described how to execute system commands from Java applications. A long time ago I wrote my first article on this topic (How to execute system commands from Java), and more recently I wrote an updated version of that article titled "Executing system commands from Java using the ProcessBuilder and Process classes".

Given that introduction -- if you're interested in learning how to execute a Unix or Linux system pipeline (pipe) command from a Java application, you're in the right place.

A Java KeyStroke, KeyEvent, Action, InputMap, and ActionMap example

I don't know if this is the "proper" way to handle having multiple keystrokes for one action, but until I find a better approach I thought I'd share this here.

Java textarea cursor/caret position

If you need to get the position of the caret (cursor) in a JTextComponent (++JTextField, JTextArea JEditorPane or JTextPane), this turns out the be easy. Just use the getCaretPosition method of these classes, as shown here:

Java font size - how to change the JTextArea, JTextPane, JEditorPane font size

I'm currently writing a customized text editor in Java, and as part of that, I want to make it easy for the user to increase or decrease the font size in the text editing area (technically a JTextPane). I didn't expect this to be easy, but I've been pleasantly surprised that the following approach seems to work just fine:

Java, Mac, and the Dock: How to handle drop events to a Mac OS X Dock icon

Lately I've been doing a lot of Java programming on Apple's Mac OS X platform, and my most recent effort has been to handle drag and drop events in my Java Swing application. Not satisfied to handle "simple" drag and drop events, I decided I wanted to take my application even farther, and let users drag files and images to my Java application icon in the Mac Dock.

Hey Toyota, recall my 2006 RAV4

All the Toyota recalls in the news lately remind me of the problem I've had with a noise in the steering column of my 2006 Toyota RAV4, which leads me to wonder, Hey Toyota, where's my recall?

Sun's Jonathan Schwartz resigns with a Twitter haiku

As part of the early fallout from Oracle's acquisition of Sun, Sun CEO Jonathan Schwartz has resigned from Sun, leaving with a parting haiku on Twitter. (See haiku on Wikipedia.)

Mr. Schwartz struck me as an interesting CEO. He seemed like one of the first CEOs to post his ideas on a blog, and his strategy of trying to make Sun a more "open" company in an effort to save them was very interesting.

Improve your MacBook battery life

Wow, I'm feeling pretty dumb at the moment ... I had no idea I was supposed to calibrate my MacBook Pro battery every month. I just found this out while trying to help a friend who was having some MacBook battery problems.

Java exec - execute system processes with Java ProcessBuilder and Process (part 1)

I've been thinking about rewriting my old article on how to execute system processes from a Java application for a while now (Running system commands from Java applications), but it's a topic that quickly becomes complicated if you want to do it right, so I kept postponing it until I could give it some quality time in a real-world project.

I've finally had an opportunity to test this in a real-world Java application on a current project, so while I'm still not finished with this, I thought I'd share what I've learned so far.

Java exec - execute system processes with Java ProcessBuilder and Process (part 2)

<< Back to "Java exec with ProcessBuilder and Process, part 1"

A complete Java class that executes a system command

Now that you've seen that snippet of code, here's a complete Java class named ProcessBuilderExample that can execute a Unix/Linux system command:

Syndicate content