Spawning a .lnk windows shortcut with node.js gives “UNKNOWN” error

房东的猫 提交于 2019-12-11 08:18:02

问题


I'm having a game spawned as a child process. It all works nice and well with the game's original .exe file. However, I'd like it to execute minimized, and the only way to do it as far as I can tell is to create a windows shortcut (.lnk file, in the same directory) and set the launch options to minimized. Node.js doesn't like that:

    internal/child_process.js:313
    throw errnoException(err, 'spawn');
    ^

Error: spawn UNKNOWN
    at exports._errnoException (util.js:1026:11)
    at ChildProcess.spawn (internal/child_process.js:313:11)
    at exports.spawn (child_process.js:380:9)
    at ExecDom4Server (D:\Google Drive\Clockwork Hounds stuff\MrClockworkBot\v10
\MrClockworkBot.js:568:42)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)

The game itself has a few specific arguments on graphic settings but none to launch it minimized either. Here's the particular code:

function execDom4Server(name, args)
{
    var spawn = require('child_process').spawn;
    childrenProcesses[name.toLowerCase()] = spawn(dom4root + "dom4.exe.lnk", args);
    updateDom4Games();
}

I've looked everywhere for this, but I suppose it's fairly specific. I don't know if it's just node.js being unable to handle .lnk files. Any pointers that you can give me would be greatly appreciated!


回答1:


This should work if you use the shell option of spawn()

spawn('application.lnk', args, { shell: true })


来源:https://stackoverflow.com/questions/41497183/spawning-a-lnk-windows-shortcut-with-node-js-gives-unknown-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!