【问题标题】:How to exit putty without killing powershell process?如何在不杀死powershell进程的情况下退出腻子?
【发布时间】:2021-12-02 18:34:32
【问题描述】:

我正在使用 powershell 在 linux 服务器上托管一个不和谐机器人。但是每当我退出腻子时,它都会杀死 powershell 进程。如何让它继续运行?

【问题讨论】:

标签: node.js powershell server putty remote-server


【解决方案1】:

在 linux 端,使用& 在后台运行进程,并在用户退出 shell(putty 会话)时使用nohup 命令继续运行:

# Run your command 
[user@server ~]$ nohup pwsh -Command 'Do-Thing -Foo a -Bar b' &

# Or run a script
[user@server ~]$ nohup pwsh -File /path/to/script.ps1 &

它将在jobs 中显示为作业,但仅在您断开连接之前:

[user@server ~]$ jobs
[1]+  Running         nohup pwsh -Command 'Sleep -100' &

# bring the job to the foreground and kill it, for example
[user@server ~]$ fg 1
[user@server ~]$ ^C

断开连接后,作业将自行运行。使用ps 查找正在运行的进程并在需要时将其终止:

[user@server ~]$ ps -e | grep pwsh
30975 ?        00:00:01 pwsh

[user@server ~]$ kill 30975

如果您想要更强大的功能(例如崩溃时自动重启),您可以将其设置为 run as a service,但具体步骤可能因 linux 的不同而异。

【讨论】:

  • 考虑发布您对许多重复问题的答案。
【解决方案2】:

在powershell中使用:

powershell -noExit "cf ssh app_name"

可以设置一个powershell函数来缩短它:

function psne { powershell -NoExit $args[0]}

然后运行

psne "cf ssh app_name"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-27
    相关资源
    最近更新 更多