我正在尝试用 node.js 做一个小应用程序,它可以在 mac 上运行并执行一些命令。
我已经成功地使用 spawn 来运行命令行,例如 xcodebuild,但是当我尝试打开 iOS 模拟器时,xcrun 似乎不起作用。我可以通过键入以下内容在终端上打开:
xcrun instruments -w 'iPhone 5s (9.2)' -t <template>
但是,如果我使用节点并尝试像这样使用 spawn:
var args = ['instruments', '-w', `iPhone 5s (9.2)`, '-t', 'noTemp'];
var xcrun = spawn('xcrun', args);
所以它让我想到它可能有一些限制打开应用程序?我试图运行:
var args = ['/Applications/Spotify.app'];
var xcrun = spawn('open', args);
什么也没有发生。我找不到与此相关的任何内容。我的问题是:无论如何都可以使用 node.js spawn 打开应用程序?如果有,有人知道我的代码有什么问题吗?
如果需要,这是完整的代码:
var args = ['instruments', '-w', `${fullDevice}`, '-t', 'noTemp'];
var xcrun = spawn('xcrun', args);
xcrun.stdout.on('data', (data)=>{
console.log(data.toString('utf8'));
})
xcrun.on('close', (code) => {
socket.emit({
time: commands.getCurrentTime(),
type: 'success',
log: 'Device booted...'
});
callback();
if (code !== 0) {
console.log(`open process exited with code ${code}`);
}
});
OBS:如果我运行这段代码,应用程序不会终止,程序不会继续,也不会发生任何事情。
编辑:更改:
xcrun.on('data', (data)=>{
至:
xcrun.stdout.on('data', (data)=>{