我想在Windows CMD控制台中运行两个命令。
在Linux中我会这样做
touch thisfile ; ls -lstrh
在Windows上是怎么做的呢?
我想在Windows CMD控制台中运行两个命令。
在Linux中我会这样做
touch thisfile ; ls -lstrh
在Windows上是怎么做的呢?
当前回答
cmd /c ipconfig /all & Output.txt
该命令执行命令并在一个命令中打开Output.txt文件
其他回答
当您尝试在一行中使用或操作变量时,请注意它们的内容!例如,如下所示的变量
PATH=C:\程序文件(x86)\某处;“C: \企业\酷工具”;% USERPROFILE % \ AppData \当地\ \ WindowsApps微软;
可能会导致很多无法处理的麻烦,如果你使用它作为%PATH%
右括号终止组语句 双引号不允许使用%PATH%来处理圆括号问题 像%USERPROFILE%这样的引用变量将包含什么?
为了同时执行两个命令,必须在两个命令之间加上&(&)符号。像这样:
color 0a & start chrome.exe
干杯!
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\" &暂停&退出
这就像一个咒语——RegAsm在文件上运行并显示其结果,然后显示“按任意键继续…”提示符,然后当按下一个键时命令提示符窗口关闭。
P.S.对于其他可能感兴趣的人,你可以使用以下.reg文件条目来添加一个dllfile关联到.dll文件,然后再添加一个RegAsm命令扩展名(注意转义的引号和反斜杠):
[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"
现在我有了一个很好的右击菜单来注册程序集。
我试图创建批处理文件启动提升cmd,并使其运行2个单独的命令。 当我使用&或&&字符时,我遇到了一个问题。例如,这是我的批处理文件中的文本:
powershell.exe -Command "Start-Process cmd \"/k echo hello && call cd C:\ \" -Verb RunAs"
我得到解析错误:
经过几次猜测,我发现,如果你用“&&”这样的引号包围&&,它是有效的:
powershell.exe -Command "Start-Process cmd \"/k echo hello "&&" call cd C:\ \" -Verb RunAs"
结果如下:
也许这能帮到别人:)
我尝试在同一个窗口中有两个ping,它是在同一行上的串行命令。完成第一个命令后,执行第二个命令。
解决方案是在Windows 7命令提示符中结合start /b。
像往常一样启动,不带/b,并在单独的窗口中启动。
在同一行中用于启动的命令是:
start /b command1 parameters & command2 parameters
无论如何,如果您希望解析输出,我不建议使用这种方法。 我注意到输出在命令的输出之间被打乱了。