Skip to content

Commit f6b5052

Browse files
committed
Basic PuTTY support, Ref. #368
1 parent 39e98e3 commit f6b5052

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

console-executor.js

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,48 @@
11
const { spawn } = require('child_process');
2+
const { app } = require('electron');
3+
const path = require('path');
4+
5+
async function setPATHEnv() {
6+
const puttyLookup = [
7+
path.join(__dirname, 'dist', 'putty'),
8+
path.join(path.dirname(app.getPath('exe')), 'dist', 'putty')
9+
];
10+
11+
// prevent adding duplicates
12+
let extra = [
13+
...puttyLookup,
14+
].filter((dir) => {
15+
return process.env.PATH.indexOf(dir) < 0;
16+
});
17+
extra.push(process.env.PATH);
18+
process.env.PATH = extra.join(";");
19+
}
220

321
exports.openConsole = async (consoleRequest) => {
4-
const genericConsoleCommand = 'xfce4-terminal --tab -T "%d" -e "telnet %h %p"';
22+
// const genericConsoleCommand = 'xfce4-terminal --tab -T "%d" -e "telnet %h %p"';
23+
const genericConsoleCommand = 'putty.exe -telnet %h %p -loghost "%d"';
24+
525
const command = prepareCommand(genericConsoleCommand, consoleRequest);
26+
27+
console.log(`Setting up PATH`);
28+
await setPATHEnv();
29+
630
console.log(`Starting console with command: '${command}'`);
731

832
let consoleProcess = spawn(command, [], {
933
shell :true
1034
});
1135

1236
consoleProcess.stdout.on('data', (data) => {
13-
console.log(`Console is producing: ${data.toString()}`);
37+
console.log(`Console stdout is producing: ${data.toString()}`);
38+
});
39+
40+
consoleProcess.stderr.on('data', (data) => {
41+
console.log(`Console stderr is producing: ${data.toString()}`);
42+
});
43+
44+
consoleProcess.on('close', (code) => {
45+
console.log(`child process exited with code ${code}`);
1446
});
1547
}
1648

0 commit comments

Comments
 (0)