As esteemed moritz has suggested, this code is much cleaner, and includes diagnostics for the close. One thing to add; make sure that the last arg in the @arg array is '2>&1'. By default, the pipe operation of open (and shell) only sends stdout. If your application prints any information to stderr, it will be lost.