最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

process - Ger current command in Deno - Stack Overflow

programmeradmin2浏览0评论

I'm running my deno program like this

deno task dev

which corresponds to

deno run --allow-all --watch src/server/main.ts --watch-client

Within my main.ts I want to get the current full Deno command, not just the args (so either deno task dev or deno run --allow-all --watch src/server/main.ts --watch-client).

Deno.args doesn't help as it returns only ['--watch-client'].

edit:

One way could be using Deno.pid as reference and run Get-WmiObject Win32_Process -Filter "ProcessId = 27096" (where 27096 is my Deno.pid) and then parse output an look for CommandLine, but it's PowerShell / Windows only

edit2: I managed obtaining the information in Windows via powershell like this:

const command = new Deno.Command("powershell.exe", { 
        args: [`Get-WmiObject Win32_Process -Filter "ProcessId = ${Deno.pid}"`]
    })

const out = await command.output();
const info = new TextDecoder().decode(out.stdout);
const commandLine = /^CommandLine\s*:\s*(.*)$/gm.exec(info)![1];
console.log(commandLine);

However I'm still looking for a more cross platform solution

发布评论

评论列表(0)

  1. 暂无评论