-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: parsing for non-english systems, part 2 (#26)
* Removed null type from ExecResponse (as far as I can tell, exec always returns strings) * Always use the language env vars in execAsync (since the output is always assumed to be in English) * Removed redundant env vars from cmd input to execAsync * Added a bit of documentation to the env vars
- Loading branch information
Showing
4 changed files
with
26 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
"use strict"; | ||
|
||
const { exec } = require("child_process"); | ||
const util = require("util"); | ||
const execAsync = util.promisify(exec); | ||
import { ExecResponse } from "../types"; | ||
import { exec } from "child_process"; | ||
|
||
export default execAsync; | ||
export default function execAsync(cmd: string): Promise<ExecResponse> { | ||
return new Promise((resolve, reject) => { | ||
exec(cmd, { | ||
// The output from lp and lpstat is parsed assuming the language is English. | ||
// LANG=C sets the language and the SOFTWARE variable is necessary | ||
// on MacOS due to a detail in Apple's CUPS implementation | ||
// (see https://unix.stackexchange.com/a/33836) | ||
env: { | ||
SOFTWARE: "", | ||
LANG: "C" | ||
} | ||
}, (err, stdout, stderr) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve({stdout, stderr}); | ||
} | ||
}); | ||
}); | ||
} |