shell - 为什么我在 cmd 中的 1 行命令不起作用?
问题描述
bin
如果文件夹不存在,我有这个命令可以自动创建一个文件夹:
if not exist bin mkdir bin
我有另一个命令来编译 C 文件并将其放入bin
文件夹中:
gcc hello_world.c -o bin/hello_world.exe
当我像这样将命令连接在一起时:
if not exist bin mkdir bin && gcc hello_world.c -o bin/hello_world.exe
如果该bin
文件夹不存在,它可以正常工作。但是当 bin 文件夹已经存在时,第二个命令不会运行。
为什么以及如何发生这种情况?
编辑:我已经尝试过只使用 1&
但它仍然是相同的结果。
解决方案
C:\WINDOWS\system32>(if not exist bin mkdir bin) & echo %errorlevel%
1
C:\WINDOWS\system32>(if not exist bin mkdir bin) & echo %errorlevel%
0
&&
表示仅当为 0 时才运行下一条命令。%errorlevel%
更改为&
.
见https://winsourcecode.blogspot.com/2019/12/command-prompt-cheat-sheet.html
推荐阅读
- angular - Angular 8 hot/live reload 无法正常工作
- javascript - 从 CDN 包含引导程序时,类的自动完成在智能感知中不起作用
- c - 缓存是否有可能超过 100% 的未命中率
- github - 当另一个存储库创建新版本时触发 GitHub 操作
- c++ - 应该 C++ std::future
方法命名为 is_ready() 还是 ready()? - laravel - 如何以更新形式为 Laravel 检索图像数据库
- vue.js - How do I change the URL of the page in Nuxt SSR mode without reloading the whole page?
- regex - 基于引用 URL 字符串的 htaccess 重定向
- javascript - 如何使用 JS 扩展向网站添加自定义框和文本
- concurrency - 在对 n 个不同的用户进行并发测试时,需要在 jmeter 中登录之前执行需要身份验证的操作