Skip to content

Commit 2088fde

Browse files
committed
fix: normalize line endings in SSH script execution
1 parent bbc591b commit 2088fde

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

lib/ssh/ssh-controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,15 @@ export class MxaCtl {
386386
throw new Error(`文件 ${file} 不存在: ${fullPath}`)
387387
}
388388
const fileContent = await readFile(fullPath, { encoding: 'utf8' })
389+
const normalizedContent = fileContent.replace(/\r\n/g, '\n').replace(/\r/g, '\n')
389390
if (sudo) {
390-
const res = await this.ssh.exec('sudo', ['bash', '-c', fileContent], {
391+
const res = await this.ssh.exec('sudo', ['bash', '-c', normalizedContent], {
391392
...this.execOptions({ sudo, ...restOptions }),
392393
stream: 'both',
393394
})
394395
return { ...res, stdout: this.removeSudoPrompt(res.stdout) }
395396
}
396-
return await this.ssh.exec('bash', ['-c', fileContent], {
397+
return await this.ssh.exec('bash', ['-c', normalizedContent], {
397398
...this.execOptions({ sudo, ...restOptions }),
398399
stream: 'both',
399400
})

0 commit comments

Comments
 (0)