c++ - 在 WSL 中通过 C++ 关闭和重新启动 PC
问题描述
这是我用 c++ 关闭 PC 的程序,我使用 vs 代码编辑器和 WSL 来运行这个程序:
#include<iostream>
#include<stdlib.h>
int main()
{
system("C:\\Windows\\System32\\shutdown /i ");
}
我收到了这条消息sh: 1: C:WindowsSystem32shutdown: not found
。
解决方案
确保使用适当的路径。通过 Linux 进行 WSL 的正确形式"/mnt/c/Windows/System32/shutdown.exe"
如 prog-fh 和 code_fodder 所述。
所以这会起作用:(我没有在 WSL 中测试过,但上面的用户做了并且知道得更好)
std::system("/mnt/c/Windows/System32/shutdown.exe /i");
或者对于关机,您也可以使用s
:
std::system("/mnt/c/Windows/System32/shutdown.exe /s");
同样,要重新启动,请使用r
:
std::system("/mnt/c/Windows/System32/shutdown.exe /r");
推荐阅读
- angular - Angular所有菜单项以访问当前ID
- node.js - MongoDb 通过 _id 使用 Node 查询
- c++ - CMake复制DLL/将“bin”添加到共享库的路径
- r - 如何告诉 ddply 忽略 hms 而只查看 ymd?
- git - Jenkins在webhook触发时获取错误的分支
- html - 需要帮助理解嵌套
- python - 扩展Robotframework AppiumLibrary以调用appium execute_script函数时如何传递参数
- python - 从 numpy 中的数学表达式中删除 for 循环
- loops - 带有 2 个变量的 for 循环
- javascript - 这是我一段时间以来一直遇到的错误“找不到模块:无法解析'../lib'”,不知道问题是什么