我用电子构建了一个应用程序,在根目录中我有一个库。我想从我的应用程序运行子进程,所以我像这样使用它:
$url = 'https://servername:port/api/sam/raw_app_usage_property_values?criteria={"and":[["process","=","visio.exe"]]}&limit=100&columns[]=process&columns[]=computer_id&columns[]=last_used'
# option 1. get all results, we see a full list of processes, full string returned
#$results = Invoke-WebRequest -Uri $url -Method GET -Headers $headers
#write-host $results
# option 2. get all results but break them down as part of the request. Only one result returned - @{total=10; rows=System.Object[]}
#$results = Invoke-WebRequest -Uri $url -Method GET -Headers $headers | ConvertFrom-Json
#write-host $results
# option 3. use a different method, which supposedly breaks down the request natively. Only one result returned - @{total=10; rows=System.Object[]}
#$results = Invoke-RestMethod -Uri $url -Method GET -Headers $headers
#write-host $results
# option 4. get content directly from file, only one result returned - @{total=10; rows=System.Object[]}
#$results = (Get-Content -path "C:\temp\raw_app_usage_property_values.json" -raw)
# is there anything in the array?
foreach ($result in $results) {
write-host $result
}
当我使用spawn(path.resolve(LIB_PATH +'command_to_run')
运行应用时,此功能正常。但是如果我使用电子打包器进行构建,似乎它找不到命令。我收到此错误:
为什么会这样?我正在研究很多,但找不到任何东西。
由于
答案 0 :(得分:1)
找到解决方案。当我运行npm start
时,我可以直接从项目的根目录中调用./command_to_run
。但是当我创建.app文件时,我需要添加:path.dirname(require.main.filename) + 'command_to_run'
。然后它会调用我目录根目录中的文件。