sách gpt4 ai đã đi

deno - 如何关闭计算机(主机)

In lại 作者:行者123 更新时间:2023-12-02 18:04:23 25 4
mua khóa gpt4 Nike

我知道这听起来很奇怪,但我有一个情况,Deno 需要关闭自己的主机(并因此杀死自己的进程)。这可能吗?

我特别需要这个用于 linux (lubuntu),如果相关的话。我想这需要 sudo 权限,这很糟糕,但也是一个选择。

对于那些对细节感兴趣的人:我正在编写一个《我的世界》服务器软件,如果服务器30分钟内没有玩家,它会自行关闭以节省电量。无论如何,24/7 运行的树莓派具有局域网唤醒功能,以便它可以再次启动。启动后,服务器管理器软件将自 Action 为Linux服务启动。

1 Câu trả lời

您可以create a subprocessđể đạt được mục đích này:

await Deno.run({ cmd: ["shutdown", "-h", "now"] }).status();

Concepts

  • Deno is capable of spawning a subprocess via Deno.run.
  • --allow-run permission is required to spawn a subprocess.
  • Spawned subprocesses do not run in a security sandbox.
  • Communicate with the subprocess via the tiêu chuẩn, đầu ra chuẩnstderr streams.
  • Use a specific shell by providing its path/name and its string input switch, e.g. Deno.run({cmd: ["bash", "-c", "ls -la"]});

Xem thêmcommand line - Shutdown from terminal without entering password? - Ask Ubuntu了解如何避免需要 su-đu-t Gọi shutdown 或可以从 Deno 调用的替代命令。

关于deno - 如何关闭计算机(主机),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73641180/

25 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com