FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonVSCode/python_files/shell_exec.py at main · Timorleiderman/pythonVSCode · GitHub
Timorleiderman
/
pythonVSCode
Public
forked from
DonJayamanne/pythonVSCode
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonVSCode
/
python_files
/
shell_exec.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
42 lines (34 loc) · 1.37 KB
Breadcrumbs
pythonVSCode
/
python_files
/
shell_exec.py
Copy path
File metadata and controls
42 lines (34 loc) · 1.37 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import
subprocess
import
sys
# This is a simple solution to waiting for completion of commands sent to terminal.
# 1. Intercept commands send to a terminal
# 2. Send commands to our script file with an additional argument
# 3. In here create a file that'll log the progress.
# 4. Calling code monitors the contents of the file to determine state of execution.
# Last argument is a file that's used for synchronizing the actions in the terminal with the calling code in extension.
lock_file
=
sys
.
argv
[
-
1
]
shell_args
=
sys
.
argv
[
1
:
-
1
]
print
(
"Executing command in shell >> "
+
" "
.
join
(
shell_args
))
with
open
(
lock_file
,
"w"
)
as
fp
:
try
:
# Signal start of execution.
fp
.
write
(
"START
\n
"
)
fp
.
flush
()
subprocess
.
check_call
(
shell_args
,
stdout
=
sys
.
stdout
,
stderr
=
sys
.
stderr
)
# Signal start of execution.
fp
.
write
(
"END
\n
"
)
fp
.
flush
()
except
Exception
:
import
traceback
print
(
traceback
.
format_exc
())
# Signal end of execution with failure state.
fp
.
write
(
"FAIL
\n
"
)
fp
.
flush
()
try
:
# ALso log the error for use from the other side.
with
open
(
lock_file
+
".error"
,
"w"
)
as
fpError
:
fpError
.
write
(
traceback
.
format_exc
())
except
Exception
:
pass
Back
|
FazBrowse Home
|
New Git URL