Capture error before backgrounding?
Hey guys,
First, I apologize if this is the wrong forum to ask my question but I'm new here. Here's my question: I'm writing a bash script to execute ./MyCommand then continue to do other things. Specifically, I'm trying to capture the errno of ./MyCommand in order to gracefully clean up any preprocessing I've done. So far I've come up with this: Code:
# Some preprocessing is done Therefore, I've tried this: Code:
# Some preprocessing is done This comes to my question: How can I merge these two methods? I'd like to background my process, while at the same time capture the error of the actual command so I can do the appropriate clean up? Thanks in advance! |
See the Advanced Bash-Scripting Guide, Chapter 23. Functions, for discussion on where in the script to declare a function, and how to call it.
Code:
function declaration before the call Code:
# Some preprocessing is done |
Hi.
The bash built-in wait will wait for a process to complete and report the status. One captures the process ID of the most recent process placed in the background with $! Code:
#!/bin/bash - Code:
$ ./s1 See bash's documentation on this: help wait ... cheers, makyo |
I wonder why you bothered to background the job, since the next step is to ask if it worked. Why not just leave it in the foreground? Well, maybe it was just an over-simplified example!!
Fedora Development |
All times are GMT -5. The time now is 08:59 PM. |