16

For example, in Bash, I can do this:

emacs foo.txt &

Is there any equivalent in Windows? I can't seem to figure out a way to do this with the windows version of emacs.

Jason Baker
  • 1,229
  • 6
  • 20
  • 26

7 Answers7

23

The command to launch programs from the command-line in Windows is "start"

Starts a separate window to run a specified program or command.

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/AFFINITY <hex affinity>] [/WAIT] [/B] [command/program]
      [parameters]

    "title"     Title to display in  window title bar.
    path        Starting directory
    B           Start application without creating a new window. The
                application has ^C handling ignored. Unless the application
                enables ^C processing, ^Break is the only way to interrupt
                the application
    I           The new environment will be the original environment passed
                to the cmd.exe and not the current environment.
    MIN         Start window minimized
    MAX         Start window maximized
    SEPARATE    Start 16-bit Windows program in separate memory space
    SHARED      Start 16-bit Windows program in shared memory space
    LOW         Start application in the IDLE priority class
    NORMAL      Start application in the NORMAL priority class
    HIGH        Start application in the HIGH priority class
    REALTIME    Start application in the REALTIME priority class
    ABOVENORMAL Start application in the ABOVENORMAL priority class
    BELOWNORMAL Start application in the BELOWNORMAL priority class
    AFFINITY    The new application will have the specified processor
                affinity mask, expressed as a hexadecimal number.
    WAIT        Start application and wait for it to terminate

You may want to use the MIN option to start a program minimized

Kevin Kuphal
  • 9,134
  • 1
  • 35
  • 41
  • 2
    FYI, the correct command in this case is "start /B emacs foo.txt". Otherwise, it runs in its own console window, which is acceptable, but annoying. :-) – Jason Baker Jun 25 '09 at 15:26
3

I don't know if it will be sufficient, but try

start emacs foo.txt

It will not go into background but it will rather start separate cmd.exe window for the command.

kubanczyk
  • 13,812
  • 5
  • 41
  • 55
2

HaHa,I successed ,To use sublime text3 as a server of markdown preview is my propose,after I closed sublime text's window,i won't work. I'd try many methods,at last it works. first,you should create a bat to start this program.

start  /B "" "D:\dev\sublime3\Sublime Text 3\subl.exe" "-s" "%USERPROFILE%\Dropbox\dev\apis\*.markdown" 

sencond,run this bat by schedule task.

run window+R->taskschd.msc->add a task

add a trigger to run this bat according this schedule

add this bat as a operation to execute

This result is that it works to avoid to show sublime text window.and it work conflict with sublime text normally opened.

Maybe you had guessed ,I use OmniMarkupPreviewer plugin to preview markdown.I had fixed this bug(or not perfect feature) that it uses different view id every time.

vincent
  • 21
  • 2
1

Depends on which version of Windows you're using.

In Vista you should be able to type the name of the exe in your path and have it live after the command prompt is closed.

MathewC
  • 6,957
  • 9
  • 39
  • 53
1

start calc

How to Start a Program From a Command Prompt in Windows

The START command is used at an MS-DOS prompt to start an MS-DOS-based or Windows-based program. The program is started as a separate task that can be run in the foreground or background.

Jindrich
  • 4,968
  • 8
  • 30
  • 42
1

Unfortunately I do not think that this is possible.

You can do this in a Windows Scripting Host script, with something like:

Set oShell = WScript.CreateObject("WScript.Shell")
Set oProc = oShell.Run "<your command here>",0,True

Where the "0" states that the resulting window should be hidden (for other options, see the documentation at http://msdn.microsoft.com/en-us/library/d5fk67ky(VS.85).aspx) and the "true" states that you want to wait for the command to complete before your script carries on.

It would be a simple exercise to wrap this up in a generic "run this command hidden" script that you could use from the command line.

If you have Microsoft's new new PowerShell installed, then there may be an easier way to do this (I've not worked with PowerShell yet).

If you are happy to have the window minimised then you can do that with the "start" command that other mention. Unfortunately the "/B" option (which sounds like it is what you want) is only for commands and it doesn't stop windowed applications appearing on screen.

Note: which ever of the above you use to you start a program with a hidden/minimised main window, there is nothing to stop it creating new windows that are visible, or bringing the main window up and into focus, once it is running.

David Spillett
  • 22,754
  • 45
  • 67
1

sc create service and run it has special chars on the file and parameters for example

sc create ngrok "cmd /c \"c:\tmp\ngrok.exe\" http 80" type=own type=interactive
Jenny D
  • 27,780
  • 21
  • 75
  • 114
Lalo
  • 111
  • 1
  • 1
    sc create nrgok binpath="cmd /c \"c:\tmp\ngrok.exe\" http 80" type=own type=interact – Lalo Feb 20 '19 at 04:10