Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reading from console output for --status on windows and linux #184138

Merged
merged 1 commit into from Jun 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/vs/code/node/cli.ts
Expand Up @@ -188,13 +188,14 @@ export async function main(argv: string[]): Promise<any> {

const processCallbacks: ((child: ChildProcess) => Promise<void>)[] = [];

const verbose = args.verbose;
if (verbose) {
if (args.verbose) {
env['ELECTRON_ENABLE_LOGGING'] = '1';
}

if (args.verbose || args.status) {
processCallbacks.push(async child => {
child.stdout!.on('data', (data: Buffer) => console.log(data.toString('utf8').trim()));
child.stderr!.on('data', (data: Buffer) => console.log(data.toString('utf8').trim()));
child.stderr?.on('data', (data: Buffer) => console.log(data.toString('utf8').trim()));

await Event.toPromise(Event.fromNodeEventEmitter(child, 'exit'));
});
Expand All @@ -219,7 +220,7 @@ export async function main(argv: string[]): Promise<any> {

// returns a file path where stdin input is written into (write in progress).
try {
await readFromStdin(stdinFilePath, !!verbose); // throws error if file can not be written
await readFromStdin(stdinFilePath, !!args.verbose); // throws error if file can not be written

// Make sure to open tmp file
addArg(argv, stdinFilePath);
Expand Down Expand Up @@ -258,7 +259,7 @@ export async function main(argv: string[]): Promise<any> {
// is closed and then exit the waiting process.
let waitMarkerFilePath: string | undefined;
if (args.wait) {
waitMarkerFilePath = createWaitMarkerFileSync(verbose);
waitMarkerFilePath = createWaitMarkerFileSync(args.verbose);
if (waitMarkerFilePath) {
addArg(argv, '--waitMarkerFilePath', waitMarkerFilePath);
}
Expand Down Expand Up @@ -407,13 +408,13 @@ export async function main(argv: string[]): Promise<any> {
env
};

if (!verbose) {
if (!args.verbose) {
options['stdio'] = 'ignore';
}

let child: ChildProcess;
if (!isMacOSBigSurOrNewer) {
if (!verbose && args.status) {
if (!args.verbose && args.status) {
options['stdio'] = ['ignore', 'pipe', 'ignore']; // restore ability to see output when --status is used
}

Expand All @@ -435,13 +436,13 @@ export async function main(argv: string[]): Promise<any> {
// -a opens the given application.
spawnArgs.push('-a', process.execPath); // -a: opens a specific application

if (verbose || args.status) {
if (args.verbose || args.status) {
spawnArgs.push('--wait-apps'); // `open --wait-apps`: blocks until the launched app is closed (even if they were already running)

// The open command only allows for redirecting stderr and stdout to files,
// so we make it redirect those to temp files, and then use a logger to
// redirect the file output to the console
for (const outputType of verbose ? ['stdout', 'stderr'] : ['stdout']) {
for (const outputType of args.verbose ? ['stdout', 'stderr'] : ['stdout']) {

// Tmp file to target output to
const tmpName = randomPath(tmpdir(), `code-${outputType}`);
Expand Down