请使用cmd.exe更改目录并在该目录中运行命令 [英] use cmd.exe to change directory and run command in that directory

查看:335
本文介绍了请使用cmd.exe更改目录并在该目录中运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做的是:


  1. 更改到其他驱动器的特定目录

  2. 在该目录中运行命令例如dir

我需要使用从不同驱动器启动的cmd.exe一行执行此操作

I need to do this in one line using cmd.exe starting from a different drive

我会这样做:

c:
cd temp
dir 

所以在一个语句到目前为止我有:

so in one statement so far I have:

cmd /c c: & cd\temp & dir

但是这只是给我从目录开始的目录。我如何从c:\ temp?获得dir?

But this just gives me dir for the P: directory which I start from. How can I get dir returned from c:\temp?

我无法运行批处理文件,它必须在一行语句中。

I can't run a batch file and it must be in a one-line statement.

推荐答案

您可能想使用/ d选项调用CD,因此不仅要更改驱动器c上的当前目录,

You may want to invoke CD with the /d option, thus not only changing the current directory on drive c: but also going there (in case you are not already on that drive).

 cmd /c "cd /d c:\temp && dir"

这篇关于请使用cmd.exe更改目录并在该目录中运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆