Results 1 to 5 of 5

Thread: Howto run a CLI application as a background process?

  1. #1
    Join Date
    Apr 2009
    Beans
    6
    Distro
    Ubuntu 8.04 Hardy Heron

    Howto run a CLI application as a background process?

    Hello,

    I'd like to use HandBrakeCLI to encode videos. However, its an interactive CLI application. I'd like to start the process and send it to the background so it just runs until it finishes without interaction (daemon?).

    The HandBrakeCLI command looks something like this:

    $ HandBrakeCLI -i input.avi -o output.m4v --preset="AppleTV"

    When I run this command, the application shows me the progress continually until the encode is finished. Ideally, I'd like to immediately get back to the command prompt, then see the program running as a process using top, at least until its finished.

    I tried this command:

    $ HandBrakeCLI > /dev/null -i input.avi -o output.m4v --preset="AppleTV" &

    I thought that would work, but its not. Maybe I have the syntax wrong, not sure.

    Can someone please shed some light on this for me?

  2. #2
    Join Date
    Feb 2009
    Location
    China
    Beans
    6
    Distro
    Ubuntu Jaunty Jackalope (testing)

    Re: Howto run a CLI application as a background process?

    guess you can try this

    HandBrakeCLI -i input.avi -o output.m4v --preset="AppleTV" > /dev/null 2>/dev/null &
    2>/dev/null stand for stderr redirected to null as stdout

  3. #3
    Join Date
    Jun 2006
    Location
    Switzerland
    Beans
    Hidden!
    Distro
    Kubuntu Jaunty Jackalope (testing)

    Re: Howto run a CLI application as a background process?

    you might want to have a look at screen. It will not run things in the background but you will have a virtual terminal session in which you can have multiple terminals. You can detach it and re-attach it anytime you want. So you still have all the output info there and can check its status anytime.

  4. #4
    anewguy is offline I Ubuntu, Therefore, I Am
    Join Date
    Jun 2007
    Location
    Sometimes I visit earth
    Beans
    5,440
    Distro
    Ubuntu 12.04 Precise Pangolin

    Wink Re: Howto run a CLI application as a background process?

    I thought you could fork unattached processes from the CLI?

    Dave

  5. #5
    Join Date
    Feb 2009
    Location
    Edinburgh, Scotland
    Beans
    50
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Howto run a CLI application as a background process?

    To run a command in the background you would put & at the end of the line, for instance

    Code:
    firefox &
    would open the firefox web browser in the background, and return the prompt to you after showing you the PID of the process. After firefox is closed (the process is finished) you are told so in the terminal. The problem with this however is that closing the terminal kills the process.

    Another command you can look into is nohup, running

    Code:
    nohup firefox
    would run the process firefox, returning full control of the prompt. This is useful for initiating long processes via ssh, allowing you to logout again while the process keeps on going.

    Hopefully one of these will be what you need!

    EDIT: Firefox is an example of a command to run as I'm currently looking at a firefox browser - obviously this can be substituted with whatever command you need to run!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •