command

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 - 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.

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:

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

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

Our ThreadedStreamHandler class

Based on an old-but-good article at JavaWorld, I'm developing the following ThreadedStreamHandler class. (It's still a work-in-progress, but as mentioned, commands that don't have to be run using sudo seem to work just fine right now.)

A Java ping program/class

I've been working on a new Java networking application, and as part of network debugging, I wanted to be able to ping a server from my Java app. I thought writing a "Java ping" class/program would be straightforward, but in short, it wasn't, so I wrote a little helper class to let me call the system ping command, and use the output from it.

Unix pipe command examples (command mashups)

One of my favorite things about Unix, Linux, and Mac OS X systems is that you can create your own commands by merging other commands. There isn't any formal name for these command combinations, other than to say that you're "piping" commands together, so I recently started referring to these as "command mashups".

Here's a simple pipeline command I use all the time, creating a long list of files and piping the output into the more command:

A cool way to sort the Linux ps command by memory use

With this site hosted on a virtual server, I'm fighting quite a battle over memory use with the new LAMP architecture in place. As I try to learn more about which applications are using the most memory, I ran into this cool ps command last night that sorts the ps output by memory use, specifically by the rss field:

ps aux --sort:rss

Here's the important output from that command:

Linux find command examples

Introduction

The Linux find command is very powerful. It can search the entire filesystem for one or more files that you specify. It's an extremely helpful Linux command to understand, especially when you need to find a file or directory.

Linux yum command reference (examples)

I've been working with the CentOS Linux yum command a lot lately, so I thought I'd create a yum reference page with a lot of examples while it's still fresh in my mind. I've organized the yum commands below by task (i.e., list, install, update, information, remove).

Linux sort command examples

Introduction

As its name implies, the Unix/Linux sort command lets you sort text information. This article shares several examples of the sort command.

Sorting output of the ls command

You can use the Linux sort command to sort all kinds of output from other commands. For instance, here's an example where I sort the output of the ls -al command:

Syndicate content