Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6121801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:49:31+00:00 2026-05-23T15:49:31+00:00

Is there any way to make a background process in Mathematica so that the

  • 0

Is there any way to make a background process in Mathematica so that the external command will run but not hold up other evaluations?

startTime = AbsoluteTime[];
Run["sleep 2" (*, a magic option here perhaps? *)];
AbsoluteTime[] - startTime
(* Returns 2.016960 on my system *)

I want a version of / option for Run that will not hold up the evaluation, so that the last line in the above code will return something close to zero.

(The above will run in *nix and OSX; there doesn’t seem to be any universal/portable way to “sleep 2” in a DOS/Windows shell:
Sleeping in a batch file. Although, perhaps the easiest way to get the sleep command is to install the MS resource kit – see this answer to the Sleeping in a batch file question or the comments below.)


At the moment, the reason I want this is so that my ALSASound command given in No sound in Mathematica under linux will not stop the fireworks. But it would also be a good improvement to ALSASound and a useful thing to know in general.


Edit

The two solutions posted below rely on using the shell to spawn a new/child process using start cmd in Windows/DOS and cmd& in *nix. Is there a platform independent and/or Mathematica based solution? (Points will be awarded for the creation of a command that checks the OS using $OperatingSystem!)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:49:32+00:00Added an answer on May 23, 2026 at 3:49 pm

    As Simon points out, Switch is the correct tool for procedural conditions and is more appropriate than Piecewise. Here’s the same solution using Switch:

    BackgroundProcess[proc_String] := 
      Switch[$OperatingSystem, 
        "MacOSX" | "Unix", Run["(" <> proc <> ")&"], 
        "Windows", Run["start /b " <> proc],
         _, $Failed]
    

    You could write a wrapper function like so that handles multiple OSes.

    BackgroundProcess[proc_String] := 
     Module[{
      command = Piecewise[{
           {proc <> " &", $OperatingSystem == "MacOSX" || "Unix"}, 
           {"start /b " <> proc, $OperatingSystem == "Windows"}
         }]
        }, 
      Run[command]]
    

    The /b after start runs the process in the background, without spawning a new command window and the output is printed to stdout. You can then build upon this to include error messages, some input sanitization (e.g., don’t allow rm and the like) if you want that, and you should be all set.

    A predefined function from Mathematica (if it existed) is probably going to be along these lines. Background processes are inherently OS dependent, so there is no real “platform independent” way of doing it. Any implementation that claims to be so (like the os module in python) is basically a set of rules defined for each possible OS known to exist, so that you don’t really have to worry about the finer details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to make the background of the google charts transparent. Google
Is there any way to make sure that a table and cells it contains
Is there any way to make a background image stretch rather than repeat?
Is there any way to make Visual Studio 2008 Express store all the files
Is there any way to make Visual Studio word-wrap at 80 characters? I'm using
Is there any way to make a function (the ones I'm thinking of are
is there any way to make IE6 understand double classes, say I have a
Is there any way to make Visual Studio show the code of a control
Is there any way to make some sections of the web.config file only apply
Is there any way to make private variables (those defined in the constructor), available

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.