How do I run two commands in one line in Windows CMD?

后端 未结 19 1371
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 00:45

I want to run two commands in a Windows CMD console.

In Linux I would do it like this

touch thisfile ; ls -lstrh

How is it done on

19条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 01:14

    So, I was trying to enable the specific task of running RegAsm (register assembly) from a context menu. The issue I had was that the result would flash up and go away before I could read it. So I tried piping to Pause, which does not work when the command fails (as mentioned here Pause command not working in .bat script and here Batch file command PAUSE does not work). So I tried cmd /k but that leaves the window open for more commands (I just want to read the result). So I added a pause followed by exit to the chain, resulting in the following:

    cmd /k C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe "%1" /codebase \"%1\" & pause & exit

    This works like a charm -- RegAsm runs on the file and shows its results, then a "Press any key to continue..." prompt is shown, then the command prompt window closes when a key is pressed.

    P.S. For others who might be interested, you can use the following .reg file entries to add a dllfile association to .dll files and then a RegAsm command extension to that (notice the escaped quotes and backslashes):

    [HKEY_CLASSES_ROOT\.dll]
    "Content Type"="application/x-msdownload"
    @="dllfile"
    
    [HKEY_CLASSES_ROOT\dllfile]
    @="Application Extension"
    
    [HKEY_CLASSES_ROOT\dllfile\Shell\RegAsm]
    @="Register Assembly"
    
    [HKEY_CLASSES_ROOT\dllfile\Shell\RegAsm\command]
    @="cmd /k C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\regasm.exe \"%1\" /codebase \"%1\" & pause & exit"
    

    Now I have a nice right-click menu to register an assembly.

提交回复
热议问题