diff --git a/src/nni_manager/common/experimentStartupInfo.ts b/src/nni_manager/common/experimentStartupInfo.ts index 5675facdde..ba8bd8789b 100644 --- a/src/nni_manager/common/experimentStartupInfo.ts +++ b/src/nni_manager/common/experimentStartupInfo.ts @@ -43,7 +43,7 @@ class ExperimentStartupInfo { this.initialized = true; if (logDir !== undefined && logDir.length > 0) { - this.logDir = path.join(logDir, getExperimentId()); + this.logDir = path.join(path.normalize(logDir), getExperimentId()); } else { this.logDir = path.join(os.homedir(), 'nni', 'experiments', getExperimentId()); } diff --git a/src/nni_manager/training_service/common/util.ts b/src/nni_manager/training_service/common/util.ts index ef05ac57b3..294728ee6d 100644 --- a/src/nni_manager/training_service/common/util.ts +++ b/src/nni_manager/training_service/common/util.ts @@ -70,11 +70,11 @@ export async function validateCodeDir(codeDir: string) : Promise { */ export async function execMkdir(directory: string, share: boolean = false): Promise { if (process.platform === 'win32') { - await cpp.exec(`powershell.exe New-Item -Path ${directory} -ItemType "directory" -Force`); + await cpp.exec(`powershell.exe New-Item -Path "${directory}" -ItemType "directory" -Force`); } else if (share) { - await cpp.exec(`(umask 0; mkdir -p ${directory})`); + await cpp.exec(`(umask 0; mkdir -p '${directory}')`); } else { - await cpp.exec(`mkdir -p ${directory}`); + await cpp.exec(`mkdir -p '${directory}'`); } return Promise.resolve(); @@ -87,9 +87,9 @@ export async function execMkdir(directory: string, share: boolean = false): Prom */ export async function execCopydir(source: string, destination: string): Promise { if (process.platform === 'win32') { - await cpp.exec(`powershell.exe Copy-Item ${source} -Destination ${destination} -Recurse`); + await cpp.exec(`powershell.exe Copy-Item "${source}" -Destination "${destination}" -Recurse`); } else { - await cpp.exec(`cp -r ${source} ${destination}`); + await cpp.exec(`cp -r '${source}' '${destination}'`); } return Promise.resolve(); @@ -101,9 +101,9 @@ export async function execCopydir(source: string, destination: string): Promise< */ export async function execNewFile(filename: string): Promise { if (process.platform === 'win32') { - await cpp.exec(`powershell.exe New-Item -Path ${filename} -ItemType "file" -Force`); + await cpp.exec(`powershell.exe New-Item -Path "${filename}" -ItemType "file" -Force`); } else { - await cpp.exec(`touch ${filename}`); + await cpp.exec(`touch '${filename}'`); } return Promise.resolve(); @@ -115,9 +115,9 @@ export async function execNewFile(filename: string): Promise { */ export function runScript(filePath: string): cp.ChildProcess { if (process.platform === 'win32') { - return cp.exec(`powershell.exe -ExecutionPolicy Bypass -file ${filePath}`); + return cp.exec(`powershell.exe -ExecutionPolicy Bypass -file "${filePath}"`); } else { - return cp.exec(`bash ${filePath}`); + return cp.exec(`bash '${filePath}'`); } } @@ -128,9 +128,9 @@ export function runScript(filePath: string): cp.ChildProcess { export async function execTail(filePath: string): Promise { let cmdresult: cpp.childProcessPromise.Result; if (process.platform === 'win32') { - cmdresult = await cpp.exec(`powershell.exe Get-Content ${filePath} -Tail 1`); + cmdresult = await cpp.exec(`powershell.exe Get-Content "${filePath}" -Tail 1`); } else { - cmdresult = await cpp.exec(`tail -n 1 ${filePath}`); + cmdresult = await cpp.exec(`tail -n 1 '${filePath}'`); } return Promise.resolve(cmdresult); @@ -142,9 +142,9 @@ export async function execTail(filePath: string): Promise { if (process.platform === 'win32') { - await cpp.exec(`powershell.exe Remove-Item ${directory} -Recurse -Force`); + await cpp.exec(`powershell.exe Remove-Item "${directory}" -Recurse -Force`); } else { - await cpp.exec(`rm -rf ${directory}`); + await cpp.exec(`rm -rf '${directory}'`); } return Promise.resolve(); @@ -173,7 +173,7 @@ export function setEnvironmentVariable(variable: { key: string; value: string }) if (process.platform === 'win32') { return `$env:${variable.key}="${variable.value}"`; } else { - return `export ${variable.key}=${variable.value}`; + return `export ${variable.key}='${variable.value}'`; } } diff --git a/src/nni_manager/training_service/local/localTrainingService.ts b/src/nni_manager/training_service/local/localTrainingService.ts index 2d4d1a1745..17cfc1fab9 100644 --- a/src/nni_manager/training_service/local/localTrainingService.ts +++ b/src/nni_manager/training_service/local/localTrainingService.ts @@ -490,18 +490,18 @@ class LocalTrainingService implements TrainingService { const script: string[] = []; if (process.platform === 'win32') { script.push( - `cmd.exe /c ${localTrialConfig.command} 2>${path.join(workingDirectory, 'stderr')}`, + `cmd.exe /c ${localTrialConfig.command} 2>"${path.join(workingDirectory, 'stderr')}"`, `$NOW_DATE = [int64](([datetime]::UtcNow)-(get-date "1/1/1970")).TotalSeconds`, `$NOW_DATE = "$NOW_DATE" + (Get-Date -Format fff).ToString()`, - `Write $LASTEXITCODE " " $NOW_DATE | Out-File ${path.join(workingDirectory, '.nni', 'state')} -NoNewline -encoding utf8`); + `Write $LASTEXITCODE " " $NOW_DATE | Out-File "${path.join(workingDirectory, '.nni', 'state')}" -NoNewline -encoding utf8`); } else { - script.push(`eval ${localTrialConfig.command} 2>${path.join(workingDirectory, 'stderr')}`); + script.push(`eval ${localTrialConfig.command} 2>"${path.join(workingDirectory, 'stderr')}"`); if (process.platform === 'darwin') { // https://superuser.com/questions/599072/how-to-get-bash-execution-time-in-milliseconds-under-mac-os-x // Considering the worst case, write 999 to avoid negative duration - script.push(`echo $? \`date +%s999\` >${path.join(workingDirectory, '.nni', 'state')}`); + script.push(`echo $? \`date +%s999\` >'${path.join(workingDirectory, '.nni', 'state')}'`); } else { - script.push(`echo $? \`date +%s%3N\` >${path.join(workingDirectory, '.nni', 'state')}`); + script.push(`echo $? \`date +%s%3N\` >'${path.join(workingDirectory, '.nni', 'state')}'`); } } @@ -522,7 +522,7 @@ class LocalTrainingService implements TrainingService { if (process.platform !== 'win32') { runScriptContent.push('#!/bin/bash'); } - runScriptContent.push(`cd ${this.localTrialConfig.codeDir}`); + runScriptContent.push(`cd '${this.localTrialConfig.codeDir}'`); for (const variable of variables) { runScriptContent.push(setEnvironmentVariable(variable)); }