Sublime Text 3:无法在外部 cmd 中获取退出代码
Sublimetext 3 : Unable to get exit code in external cmd
我正在 运行使用 Windows 10 上的 GCC 从 sublimetext 3 使用 C 代码,我希望外部 cmd 在 运行 执行 exe 后显示退出代码。
这是我的 sublime-build 文件:
{
"shell_cmd" : "gcc -Wall -pedantic $file_name -o ${file_base_name}",
"working_dir" : "$file_path",
"variants":
[
{
"name": "Run",
"shell_cmd": "gcc -Wall -pedantic $file_name -o ${file_base_name} && start cmd /k ${file_path}/${file_base_name} "
}
]
}
我试过这样的事情:
"shell_cmd": "gcc -Wall -pedantic $file_name -o ${file_base_name} && start cmd /k ${file_path}/${file_base_name} & echo %errorlevel% "
这个问题是退出代码出现在 sublimetext shell 中,总是显示 0
。我猜这是外部cmd退出代码。
我希望 echo %errorlevel%
部分在新的 cmd 中执行并显示我的 exe 的退出代码,但我不知道该怎么做。
编辑:
这是屏幕截图:
running hello world
My main.exe 运行s 在新的 cmd 中,回显在 sublimetext 自己的控制台中完成。
我想这些问题可以用更好的方式来概括:
1- 如何编写此脚本以便 cmd 可以执行第二个命令?
2- 如何打开它,运行 我的 .exe,然后才显示退出代码?
编辑 2:
Here is a new screenshot.
在这里你可以看到我的代码和 sublimetext 的内部 cmd 使用我的 sublime-build 文件中的命令调用的外部 cmd。
我手动输入 echo %errorlevel%
到这个外部命令中。
我想要实现的目标是修改我的 sublime-build 文件中的命令,该文件将从 sublimetext 的内部 cmd 执行,这样外部 cmd 调用 运行s 我的代码然后才评估echo %errorlevel%
,这一切都是自动的。
您将需要使用 delayed expansion 来实现此目的。 errorlevel
在您 运行 您的命令之前设置,它希望在同一行中进行更改。使用 cmd /v
为 cmd:
启用它
"shell_cmd": "gcc -Wall -pedantic $file_name -o ${file_base_name} && start cmd /v /k ${file_path}/${file_base_name} & echo !errorlevel! "
经过一些额外的谷歌搜索,我找到了解决方案。
我需要使用 ^&
逃离 &
这是我新的 sublime-build 命令:
"shell_cmd": "gcc -Wall -pedantic $file_name -o ${file_base_name} && start cmd /V /k ${file_path}/${file_base_name} ^& echo: ^& echo: ^& echo: ^& echo program ended code : !errorlevel! "
我正在 运行使用 Windows 10 上的 GCC 从 sublimetext 3 使用 C 代码,我希望外部 cmd 在 运行 执行 exe 后显示退出代码。
这是我的 sublime-build 文件:
{
"shell_cmd" : "gcc -Wall -pedantic $file_name -o ${file_base_name}",
"working_dir" : "$file_path",
"variants":
[
{
"name": "Run",
"shell_cmd": "gcc -Wall -pedantic $file_name -o ${file_base_name} && start cmd /k ${file_path}/${file_base_name} "
}
]
}
我试过这样的事情:
"shell_cmd": "gcc -Wall -pedantic $file_name -o ${file_base_name} && start cmd /k ${file_path}/${file_base_name} & echo %errorlevel% "
这个问题是退出代码出现在 sublimetext shell 中,总是显示 0
。我猜这是外部cmd退出代码。
我希望 echo %errorlevel%
部分在新的 cmd 中执行并显示我的 exe 的退出代码,但我不知道该怎么做。
编辑: 这是屏幕截图:
running hello world
My main.exe 运行s 在新的 cmd 中,回显在 sublimetext 自己的控制台中完成。
我想这些问题可以用更好的方式来概括:
1- 如何编写此脚本以便 cmd 可以执行第二个命令?
2- 如何打开它,运行 我的 .exe,然后才显示退出代码?
编辑 2:
Here is a new screenshot.
在这里你可以看到我的代码和 sublimetext 的内部 cmd 使用我的 sublime-build 文件中的命令调用的外部 cmd。
我手动输入 echo %errorlevel%
到这个外部命令中。
我想要实现的目标是修改我的 sublime-build 文件中的命令,该文件将从 sublimetext 的内部 cmd 执行,这样外部 cmd 调用 运行s 我的代码然后才评估echo %errorlevel%
,这一切都是自动的。
您将需要使用 delayed expansion 来实现此目的。 errorlevel
在您 运行 您的命令之前设置,它希望在同一行中进行更改。使用 cmd /v
为 cmd:
"shell_cmd": "gcc -Wall -pedantic $file_name -o ${file_base_name} && start cmd /v /k ${file_path}/${file_base_name} & echo !errorlevel! "
经过一些额外的谷歌搜索,我找到了解决方案。
我需要使用 ^&
&
这是我新的 sublime-build 命令:
"shell_cmd": "gcc -Wall -pedantic $file_name -o ${file_base_name} && start cmd /V /k ${file_path}/${file_base_name} ^& echo: ^& echo: ^& echo: ^& echo program ended code : !errorlevel! "