Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
dd7709ec
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dd7709ec
编写于
3月 11, 2016
作者:
I
isidor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
stdfork respect stderr
fixes #221
上级
cdc060a0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
69 addition
and
22 deletion
+69
-22
extensions/typescript/src/utils/electron.ts
extensions/typescript/src/utils/electron.ts
+19
-8
extensions/typescript/src/utils/electronForkStart.ts
extensions/typescript/src/utils/electronForkStart.ts
+16
-3
src/vs/base/node/stdFork.ts
src/vs/base/node/stdFork.ts
+18
-8
src/vs/base/node/stdForkStart.js
src/vs/base/node/stdForkStart.js
+16
-3
未找到文件。
extensions/typescript/src/utils/electron.ts
浏览文件 @
dd7709ec
...
...
@@ -37,7 +37,7 @@ function generatePipeName(): string {
return
path
.
join
(
os
.
tmpdir
(),
randomName
+
'
.sock
'
);
}
function
generatePatchedEnv
(
env
:
any
,
stdInPipeName
:
string
,
stdOutPipeName
:
string
):
any
{
function
generatePatchedEnv
(
env
:
any
,
stdInPipeName
:
string
,
stdOutPipeName
:
string
,
stdErrPipeName
:
string
):
any
{
// Set the two unique pipe names and the electron flag as process env
var
newEnv
:
any
=
{};
...
...
@@ -47,6 +47,7 @@ function generatePatchedEnv(env:any, stdInPipeName:string, stdOutPipeName:string
newEnv
[
'
STDIN_PIPE_NAME
'
]
=
stdInPipeName
;
newEnv
[
'
STDOUT_PIPE_NAME
'
]
=
stdOutPipeName
;
newEnv
[
'
STDERR_PIPE_NAME
'
]
=
stdErrPipeName
;
newEnv
[
'
ATOM_SHELL_INTERNAL_RUN_AS_NODE
'
]
=
'
1
'
;
return
newEnv
;
...
...
@@ -70,29 +71,38 @@ export function fork(modulePath: string, args: string[], options: IForkOptions,
callback
(
err
,
null
);
};
// Generate t
wo
unique pipe names
// Generate t
hree
unique pipe names
var
stdInPipeName
=
generatePipeName
();
var
stdOutPipeName
=
generatePipeName
();
let
stdErrPipeName
=
generatePipeName
();
var
newEnv
=
generatePatchedEnv
(
options
.
env
||
process
.
env
,
stdInPipeName
,
stdOutPipeName
);
var
newEnv
=
generatePatchedEnv
(
options
.
env
||
process
.
env
,
stdInPipeName
,
stdOutPipeName
,
stdErrPipeName
);
var
childProcess
:
cp
.
ChildProcess
;
// Begin listening to stderr pipe
let
stdErrServer
=
net
.
createServer
((
stdErrStream
)
=>
{
// From now on the childProcess.stderr is available for reading
childProcess
.
stderr
=
stdErrStream
;
});
stdErrServer
.
listen
(
stdErrPipeName
);
// Begin listening to stdout pipe
var
server
=
net
.
createServer
((
s
tream
)
=>
{
let
stdOutServer
=
net
.
createServer
((
stdOutS
tream
)
=>
{
// The child process will write exactly one chunk with content `ready` when it has installed a listener to the stdin pipe
stream
.
once
(
'
data
'
,
(
chunk
:
Buffer
)
=>
{
st
dOutSt
ream
.
once
(
'
data
'
,
(
chunk
:
Buffer
)
=>
{
// The child process is sending me the `ready` chunk, time to connect to the stdin pipe
childProcess
.
stdin
=
<
any
>
net
.
connect
(
stdInPipeName
);
// From now on the childProcess.stdout is available for reading
childProcess
.
stdout
=
stream
;
childProcess
.
stdout
=
st
dOutSt
ream
;
resolve
(
childProcess
);
});
});
server
.
listen
(
stdOutPipeName
);
s
tdOutS
erver
.
listen
(
stdOutPipeName
);
var
serverClosed
=
false
;
var
closeServer
=
()
=>
{
...
...
@@ -100,7 +110,8 @@ export function fork(modulePath: string, args: string[], options: IForkOptions,
return
;
}
serverClosed
=
true
;
server
.
close
();
stdOutServer
.
close
();
stdErrServer
.
close
();
};
// Create the process
...
...
extensions/typescript/src/utils/electronForkStart.ts
浏览文件 @
dd7709ec
...
...
@@ -26,9 +26,11 @@ var log = (function() {
var
stdInPipeName
=
process
.
env
[
'
STDIN_PIPE_NAME
'
];
var
stdOutPipeName
=
process
.
env
[
'
STDOUT_PIPE_NAME
'
];
var
stdErrPipeName
=
process
.
env
[
'
STDERR_PIPE_NAME
'
];
log
(
'
STDIN_PIPE_NAME:
'
+
stdInPipeName
);
log
(
'
STDOUT_PIPE_NAME:
'
+
stdOutPipeName
);
log
(
'
STDERR_PIPE_NAME:
'
+
stdErrPipeName
);
log
(
'
ATOM_SHELL_INTERNAL_RUN_AS_NODE:
'
+
process
.
env
[
'
ATOM_SHELL_INTERNAL_RUN_AS_NODE
'
]);
// stdout redirection to named pipe
...
...
@@ -44,8 +46,14 @@ log('ATOM_SHELL_INTERNAL_RUN_AS_NODE: ' + process.env['ATOM_SHELL_INTERNAL_RUN_A
// handle process.stdout
(
<
any
>
process
).
__defineGetter__
(
'
stdout
'
,
function
()
{
return
stdOutStream
;
});
// Create a writing stream to the stderr pipe
var
stdErrStream
=
net
.
connect
(
stdErrPipeName
);
// unref stdErrStream to behave like a normal standard out
stdErrStream
.
unref
();
// handle process.stderr
(
<
any
>
process
).
__defineGetter__
(
'
stderr
'
,
function
()
{
return
std
Out
Stream
;
});
(
<
any
>
process
).
__defineGetter__
(
'
stderr
'
,
function
()
{
return
std
Err
Stream
;
});
var
fsWriteSyncString
=
function
(
fd
,
str
,
position
,
encoding
)
{
// fs.writeSync(fd, string[, position[, encoding]]);
...
...
@@ -79,14 +87,18 @@ log('ATOM_SHELL_INTERNAL_RUN_AS_NODE: ' + process.env['ATOM_SHELL_INTERNAL_RUN_A
slicedBuffer
=
buffer
.
slice
(
off
,
off
+
len
);
}
stdOutStream
.
write
(
slicedBuffer
);
if
(
fd
===
1
)
{
stdOutStream
.
write
(
slicedBuffer
);
}
else
{
stdErrStream
.
write
(
slicedBuffer
);
}
return
slicedBuffer
.
length
;
};
// handle fs.writeSync(1, ...)
var
originalWriteSync
=
fs
.
writeSync
;
fs
.
writeSync
=
function
(
fd
,
data
,
position
,
encoding
)
{
if
(
fd
!==
1
)
{
if
(
fd
!==
1
||
fd
!==
2
)
{
return
originalWriteSync
.
apply
(
fs
,
arguments
);
}
// usage:
...
...
@@ -134,6 +146,7 @@ log('ATOM_SHELL_INTERNAL_RUN_AS_NODE: ' + process.env['ATOM_SHELL_INTERNAL_RUN_A
// Unset the custom environmental variables that should not get inherited
delete
process
.
env
[
'
STDIN_PIPE_NAME
'
];
delete
process
.
env
[
'
STDOUT_PIPE_NAME
'
];
delete
process
.
env
[
'
STDERR_PIPE_NAME
'
];
delete
process
.
env
[
'
ATOM_SHELL_INTERNAL_RUN_AS_NODE
'
];
require
(
program
);
...
...
src/vs/base/node/stdFork.ts
浏览文件 @
dd7709ec
...
...
@@ -38,7 +38,7 @@ function generatePipeName(): string {
return
path
.
join
(
os
.
tmpdir
(),
randomName
+
'
.sock
'
);
}
function
generatePatchedEnv
(
env
:
any
,
stdInPipeName
:
string
,
stdOutPipeName
:
string
):
any
{
function
generatePatchedEnv
(
env
:
any
,
stdInPipeName
:
string
,
stdOutPipeName
:
string
,
stdErrPipeName
:
string
):
any
{
// Set the two unique pipe names and the electron flag as process env
let
newEnv
:
any
=
{};
...
...
@@ -48,6 +48,7 @@ function generatePatchedEnv(env:any, stdInPipeName:string, stdOutPipeName:string
newEnv
[
'
STDIN_PIPE_NAME
'
]
=
stdInPipeName
;
newEnv
[
'
STDOUT_PIPE_NAME
'
]
=
stdOutPipeName
;
newEnv
[
'
STDERR_PIPE_NAME
'
]
=
stdErrPipeName
;
newEnv
[
'
ATOM_SHELL_INTERNAL_RUN_AS_NODE
'
]
=
'
1
'
;
return
newEnv
;
...
...
@@ -71,29 +72,37 @@ export function fork(modulePath: string, args: string[], options: IForkOpts, cal
callback
(
err
,
null
);
};
// Generate t
wo
unique pipe names
// Generate t
hree
unique pipe names
let
stdInPipeName
=
generatePipeName
();
let
stdOutPipeName
=
generatePipeName
();
let
stdErrPipeName
=
generatePipeName
();
let
newEnv
=
generatePatchedEnv
(
options
.
env
||
process
.
env
,
stdInPipeName
,
stdOutPipeName
);
let
newEnv
=
generatePatchedEnv
(
options
.
env
||
process
.
env
,
stdInPipeName
,
stdOutPipeName
,
stdErrPipeName
);
let
childProcess
:
cp
.
ChildProcess
;
// Begin listening to stderr pipe
let
stdErrServer
=
net
.
createServer
((
stdErrStream
)
=>
{
// From now on the childProcess.stderr is available for reading
childProcess
.
stderr
=
stdErrStream
;
});
stdErrServer
.
listen
(
stdErrPipeName
);
// Begin listening to stdout pipe
let
s
erver
=
net
.
createServer
((
s
tream
)
=>
{
let
s
tdOutServer
=
net
.
createServer
((
stdOutS
tream
)
=>
{
// The child process will write exactly one chunk with content `ready` when it has installed a listener to the stdin pipe
stream
.
once
(
'
data
'
,
(
chunk
:
Buffer
)
=>
{
st
dOutSt
ream
.
once
(
'
data
'
,
(
chunk
:
Buffer
)
=>
{
// The child process is sending me the `ready` chunk, time to connect to the stdin pipe
childProcess
.
stdin
=
<
any
>
net
.
connect
(
stdInPipeName
);
// From now on the childProcess.stdout is available for reading
childProcess
.
stdout
=
stream
;
childProcess
.
stdout
=
st
dOutSt
ream
;
resolve
(
childProcess
);
});
});
server
.
listen
(
stdOutPipeName
);
s
tdOutS
erver
.
listen
(
stdOutPipeName
);
let
serverClosed
=
false
;
let
closeServer
=
()
=>
{
...
...
@@ -101,7 +110,8 @@ export function fork(modulePath: string, args: string[], options: IForkOpts, cal
return
;
}
serverClosed
=
true
;
server
.
close
();
stdOutServer
.
close
();
stdErrServer
.
close
();
};
// Create the process
...
...
src/vs/base/node/stdForkStart.js
浏览文件 @
dd7709ec
...
...
@@ -28,9 +28,11 @@ var log = (function() {
var
stdInPipeName
=
process
.
env
[
'
STDIN_PIPE_NAME
'
];
var
stdOutPipeName
=
process
.
env
[
'
STDOUT_PIPE_NAME
'
];
var
stdErrPipeName
=
process
.
env
[
'
STDERR_PIPE_NAME
'
];
log
(
'
STDIN_PIPE_NAME:
'
+
stdInPipeName
);
log
(
'
STDOUT_PIPE_NAME:
'
+
stdOutPipeName
);
log
(
'
STDERR_PIPE_NAME:
'
+
stdErrPipeName
);
log
(
'
ATOM_SHELL_INTERNAL_RUN_AS_NODE:
'
+
process
.
env
[
'
ATOM_SHELL_INTERNAL_RUN_AS_NODE
'
]);
// stdout redirection to named pipe
...
...
@@ -46,8 +48,14 @@ log('ATOM_SHELL_INTERNAL_RUN_AS_NODE: ' + process.env['ATOM_SHELL_INTERNAL_RUN_A
// handle process.stdout
process
.
__defineGetter__
(
'
stdout
'
,
function
()
{
return
stdOutStream
;
});
// Create a writing stream to the stderr pipe
var
stdErrStream
=
net
.
connect
(
stdErrPipeName
);
// unref stdErrStream to behave like a normal standard out
stdErrStream
.
unref
();
// handle process.stderr
process
.
__defineGetter__
(
'
stderr
'
,
function
()
{
return
std
Out
Stream
;
});
process
.
__defineGetter__
(
'
stderr
'
,
function
()
{
return
std
Err
Stream
;
});
var
fsWriteSyncString
=
function
(
fd
,
str
,
position
,
encoding
)
{
// fs.writeSync(fd, string[, position[, encoding]]);
...
...
@@ -81,14 +89,18 @@ log('ATOM_SHELL_INTERNAL_RUN_AS_NODE: ' + process.env['ATOM_SHELL_INTERNAL_RUN_A
slicedBuffer
=
buffer
.
slice
(
off
,
off
+
len
);
}
stdOutStream
.
write
(
slicedBuffer
);
if
(
fd
===
1
)
{
stdOutStream
.
write
(
slicedBuffer
);
}
else
{
stdErrStream
.
write
(
slicedBuffer
);
}
return
slicedBuffer
.
length
;
};
// handle fs.writeSync(1, ...)
var
originalWriteSync
=
fs
.
writeSync
;
fs
.
writeSync
=
function
(
fd
,
data
,
position
,
encoding
)
{
if
(
fd
!==
1
)
{
if
(
fd
!==
1
||
fd
!==
2
)
{
return
originalWriteSync
.
apply
(
fs
,
arguments
);
}
// usage:
...
...
@@ -136,6 +148,7 @@ log('ATOM_SHELL_INTERNAL_RUN_AS_NODE: ' + process.env['ATOM_SHELL_INTERNAL_RUN_A
// Unset the custom environmental variables that should not get inherited
delete
process
.
env
[
'
STDIN_PIPE_NAME
'
];
delete
process
.
env
[
'
STDOUT_PIPE_NAME
'
];
delete
process
.
env
[
'
STDERR_PIPE_NAME
'
];
delete
process
.
env
[
'
ATOM_SHELL_INTERNAL_RUN_AS_NODE
'
];
require
(
program
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录