Execute program without tying up CMD

Discussion in 'Scripting' started by Synapse Syndrome [KGB], Apr 9, 2009.

  1. I am trying to make a .cmd script execute a program (a text editor), and
    then do other stuff, but it will not continue until that program has been
    closed.

    I have tried using the CMD command itself, with the /s switch, but that is
    not working in any way that I understand.

    How can I do this?

    Cheers

    ss.
     
    Synapse Syndrome [KGB], Apr 9, 2009
    #1
    1. Advertisements

  2. Use the Start command, e.g.

    start /b notepad.exe

    Type start /? to see the various switches.
     
    Pegasus [MVP], Apr 9, 2009
    #2
    1. Advertisements


  3. Ah, thanks. I should have of that. I use...

    start .

    ....all the time.

    Cheers

    ss.
     
    Synapse Syndrome [KGB], Apr 9, 2009
    #3
  4. Hello again

    I still cannot get it to work with the particular text editor that I am
    using. Something weird is going on.

    start /b /i "%programfiles%\JGsoft\EditPadPro6\EditPadPro.exe" "%1"

    I am using the /i switch because it is being run from a CMD instance which
    is RUNAS adminitrator, but I do not think that this has anything to do with
    it not working, as I tried with the current environment as well.

    ss.
     
    Synapse Syndrome [KGB], Apr 10, 2009
    #4
  5. Since the path to your executable contains spaces, you MUST use the "Title"
    parameter:

    start /b /i "Synapse's App"
    "%programfiles%\JGsoft\EditPadPro6\EditPadPro.exe" "%1"
     
    Pegasus [MVP], Apr 10, 2009
    #5
  6. Synapse Syndrome [KGB]

    Al Dunbar Guest

    Not exactly. The "title" parameter is required when the pathname of the
    executable is contained within double quotes. The quotes are only required
    when the executable pathname contains spaces, but they are optional and
    always allowed. In fact, one might include them when the pathname is
    determined at runtime, in which case one might not know in advance whether
    or not spaces are involved.

    If that seems an obtuse explanation, look at it from the point of view of
    the start command itself: if the first parameter starts with a double quote,
    it must be the "title" parameter, in which case executable is given by the
    second parameter. Some examples:

    these are OK:
    start notepad.exe test.cmd
    start "" "notepad.exe" test.cmd
    start "" notepad.exe test.cmd
    this is wrong:
    start "notepad.exe" test.cmd

    Actually, that is a completely valid command, it just does something you
    might not expect. It starts a batch file with the title argument set to
    "notepad.exe".

    My suggestion to avoid such a gaffe is to always include a title and always
    enclose the executable in quotes. If the title is not used for any purpose
    by the executable, just give it as "".
    Note that if the first parameter to the batch file is given enclosed in
    quotes (i.e. "file to edit.txt" the above command will pass the name to the
    executable as ""file to edit.txt"". The simplest fix is to use this syntax:
    The "~" will strip leading/trailing double quotes, but only if the are
    present.

    /Al
     
    Al Dunbar, Apr 11, 2009
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.