2017-03-07 7 views
1

실행할 때 내 컴퓨터에 저장된 실행 파일을 시작하는 전자 애플리케이션을 만들고 있습니다. exe를 단독으로 실행하면 제대로 작동하고 모든 글꼴이로드됩니다. 그러나 전자 응용 프로그램으로 실행하면 열리지 만 글꼴 파일은로드 할 수 없습니다. exe는 Visual Studio에서 제작 된 컴파일 프로젝트입니다.전자 프로젝트의 실행 파일이 리소스를로드하지 않습니다.

res 폴더를 index.html과 동일한 디렉토리에 넣지 않으려 고 시도했습니다. index.html을위한

코드 : main.js

const {app, BrowserWindow} = require('electron') 
const path = require('path') 
const url = require('url') 

function createWindow() { 
// Create the browser window. 
win = new BrowserWindow({width: 800, height: 600}) 

// and load the index.html of the app. 
win.loadURL(url.format({ 
pathname: path.join(__dirname, 'index.html'), 
protocol: 'file:', 
slashes: true 
})) 

    win.webContents.openDevTools() 

    // Emitted when the window is closed. 
    win.on('closed',() => { 

    win = null 
    }) 
} 

app.on('ready', createWindow) 

// Quit when all windows are closed. 
app.on('window-all-closed',() => { 

if (process.platform !== 'darwin') { 
    app.quit() 
} 
    }) 

app.on('activate',() => { 
    if (win === null) { 
    createWindow() 
    } 
}) 

감사에 대한

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="UTF-8"> 
    <title>Hello World!</title> 
    </head> 
    <body> 
    <h1>Hello World!</h1> 
    <script> 
     var child = require('child_process').execFile; 
     var exePath = "C:\\Users\\name\\Documents\\Visual Studio 2015\\Projects\\Ten\\Release\\Ten.exe"; 
     var parameters = ["test"]; 

     child(exePath, parameters, function(err, data){ 
     console.log(err); 
     console.log(data.toString()); 
     }) 
    </script> 
    </body> 
</html> 

코드!

답변

1

exe는 글꼴을로드하는 데 상대 경로를 사용합니까? 그렇다면, exe를 더 유연하게 변경하거나 execFile()으로 전화 할 때 선택적 작업 인수 3을 지정하여 원하는 작업 디렉토리를 지정하십시오.

var child = require('child_process').execFile; 
var exePath = "C:\\Users\\name\\Documents\\Visual Studio 2015\\Projects\\Ten\\Release"; 
var exe = exePath + "\\Ten.exe"; 
var parameters = ["test"]; 
var options = {cwd:exePath}; 

child(exePath, parameters, options, function(err, data){ 
    console.log(err); 
    console.log(data.toString()); 
    }); 

그래도 작동하지 않는다면 일종의 사용 권한 문제 일 것입니다. exe를 테스트 할 때 전자 사용자 앱이 다른 사용자로 실행되고 있습니까?

+0

감사합니다. – guavadrag0n