MCPcopy Index your code
hub / github.com/devcontainers/cli / runCommandNoPty

Function runCommandNoPty

src/spec-common/commonUtils.ts:82–180  ·  view source on GitHub ↗
(options: {
	exec: ExecFunction;
	cmd: string;
	args?: string[];
	cwd?: string;
	env?: NodeJS.ProcessEnv;
	stdin?: Buffer | fs.ReadStream | Event<string>;
	output: Log;
	print?: boolean | 'continuous' | 'onerror';
})

Source from the content-addressed store, hash-verified

80}
81
82export async function runCommandNoPty(options: {
83 exec: ExecFunction;
84 cmd: string;
85 args?: string[];
86 cwd?: string;
87 env?: NodeJS.ProcessEnv;
88 stdin?: Buffer | fs.ReadStream | Event<string>;
89 output: Log;
90 print?: boolean | 'continuous' | 'onerror';
91}) {
92 const { exec, cmd, args, cwd, env, stdin, output, print } = options;
93
94 const p = await exec({
95 cmd,
96 args,
97 cwd,
98 env,
99 output,
100 });
101
102 return new Promise<{ stdout: Buffer; stderr: Buffer }>((resolve, reject) => {
103 const stdout: Buffer[] = [];
104 const stderr: Buffer[] = [];
105
106 const stdoutDecoder = print === 'continuous' ? new StringDecoder() : undefined;
107 p.stdout.on('data', (chunk: Buffer) => {
108 stdout.push(chunk);
109 if (print === 'continuous') {
110 output.write(stdoutDecoder!.write(chunk));
111 }
112 });
113 p.stdout.on('error', (err: any) => {
114 // ENOTCONN seen with missing executable in addition to ENOENT on child_process.
115 if (err?.code !== 'ENOTCONN') {
116 throw err;
117 }
118 });
119 const stderrDecoder = print === 'continuous' ? new StringDecoder() : undefined;
120 p.stderr.on('data', (chunk: Buffer) => {
121 stderr.push(chunk);
122 if (print === 'continuous') {
123 output.write(toErrorText(stderrDecoder!.write(chunk)));
124 }
125 });
126 p.stderr.on('error', (err: any) => {
127 // ENOTCONN seen with missing executable in addition to ENOENT on child_process.
128 if (err?.code !== 'ENOTCONN') {
129 throw err;
130 }
131 });
132 const subs: Disposable[] = [];
133 p.exit.then(({ code, signal }) => {
134 try {
135 const failed = !!code || !!signal;
136 subs.forEach(sub => sub.dispose());
137 const stdoutBuf = Buffer.concat(stdout);
138 const stderrBuf = Buffer.concat(stderr);
139 if (print === true || (failed && print === 'onerror')) {

Callers 11

findGitRootFolderFunction · 0.90
getCredentialFromHelperFunction · 0.90
shellBufferExecFunction · 0.90
inspectFunction · 0.90
dockerCLIFunction · 0.90
dockerComposeCLIFunction · 0.90
isUsingSELinuxLabelsFunction · 0.90
uriToWSLFsPathFunction · 0.90
logUMaskFunction · 0.90
cleanupFunction · 0.90
getLocalUsernameFunction · 0.85

Calls 6

toErrorTextFunction · 0.85
resolveFunction · 0.85
onMethod · 0.80
execFunction · 0.70
writeMethod · 0.65
disposeMethod · 0.65

Tested by

no test coverage detected