get exit status from system() callHow to execute shell commands silently?Pipe shell command into buffer in real-timeUse vi/vim from shell to filter / format textRead from standard input and close if emptyHow to call the fzf Ag command with multiple arguments?`Read` seems to bring an extra line - how to prevent this?My status line is getting erased, so I can't print function resultHow to print an option's value to standard output?Can't echo messages from inside async functionsHow to execute commands in vim, piping the output back into the editor in real time?
Fitch Proof Question
Double or Take game
Using a microphone from the 1930s
Lie super algebra presentation of the Kähler identities
How did Shepard's and Grissom's speeds compare with orbital velocity?
Point of the the Dothraki's attack in GoT S8E3?
How long would it take for people to notice a mass disappearance?
Send iMessage from Firefox
What was the design of the Macintosh II's MMU replacement?
Can a nothic's Weird Insight action discover secrets about a player character that the character doesn't know about themselves?
How do I overfit?
As matter approaches a black hole, does it speed up?
How to change lightning-radio-group selected value programmatically?
I drew a randomly colored grid of points with tikz, how do I force it to remember the first grid from then on?
Mic, cable, pre-amp setup for acoustic guitar to perform with big band through mic and guitar amp?
How do LIGO and VIRGO know that a gravitational wave has its origin in a neutron star or a black hole?
what to look for in luxury cars like Acura/Lexus
Would glacier 'trees' be plausible?
In Avengers 1, why does Thanos need Loki?
If I readied a spell with the trigger "When I take damage", do I have to make a constitution saving throw to avoid losing Concentration?
Have I damaged my car by attempting to reverse with hand/park brake up?
Why doesn't WotC use established keywords on all new cards?
Verb "geeitet" in an old scientific text
If your medical expenses exceed your income does the IRS pay you?
get exit status from system() call
How to execute shell commands silently?Pipe shell command into buffer in real-timeUse vi/vim from shell to filter / format textRead from standard input and close if emptyHow to call the fzf Ag command with multiple arguments?`Read` seems to bring an extra line - how to prevent this?My status line is getting erased, so I can't print function resultHow to print an option's value to standard output?Can't echo messages from inside async functionsHow to execute commands in vim, piping the output back into the editor in real time?
Calling the function system("<command>") or systemlist("<command>") retrieves the stdout output from a shell call to <command>. How can I retrieve the exit status of that command?
For example, I would like to do something like this:
let output = system_call_with_exit_status("my_shell_command")
let stdout = output[0]
let exit_status = output[1]
if (exit_status != 0)
echo output
endif
The intention is to print the output from my_shell_command only if the command gives a non-zero exit status.
vimscript external-command shell
add a comment |
Calling the function system("<command>") or systemlist("<command>") retrieves the stdout output from a shell call to <command>. How can I retrieve the exit status of that command?
For example, I would like to do something like this:
let output = system_call_with_exit_status("my_shell_command")
let stdout = output[0]
let exit_status = output[1]
if (exit_status != 0)
echo output
endif
The intention is to print the output from my_shell_command only if the command gives a non-zero exit status.
vimscript external-command shell
5
:h v:shell_error
– Christian Brabandt
Apr 28 at 16:43
@ChristianBrabandt Thanks, that works.
– Jasha
Apr 28 at 16:57
@Jasha consider self-answering if youve got it figured out now
– D. Ben Knoble
Apr 28 at 17:06
@D.BenKnoble Ok, will do.
– Jasha
Apr 28 at 17:08
add a comment |
Calling the function system("<command>") or systemlist("<command>") retrieves the stdout output from a shell call to <command>. How can I retrieve the exit status of that command?
For example, I would like to do something like this:
let output = system_call_with_exit_status("my_shell_command")
let stdout = output[0]
let exit_status = output[1]
if (exit_status != 0)
echo output
endif
The intention is to print the output from my_shell_command only if the command gives a non-zero exit status.
vimscript external-command shell
Calling the function system("<command>") or systemlist("<command>") retrieves the stdout output from a shell call to <command>. How can I retrieve the exit status of that command?
For example, I would like to do something like this:
let output = system_call_with_exit_status("my_shell_command")
let stdout = output[0]
let exit_status = output[1]
if (exit_status != 0)
echo output
endif
The intention is to print the output from my_shell_command only if the command gives a non-zero exit status.
vimscript external-command shell
vimscript external-command shell
asked Apr 28 at 16:25
JashaJasha
1655
1655
5
:h v:shell_error
– Christian Brabandt
Apr 28 at 16:43
@ChristianBrabandt Thanks, that works.
– Jasha
Apr 28 at 16:57
@Jasha consider self-answering if youve got it figured out now
– D. Ben Knoble
Apr 28 at 17:06
@D.BenKnoble Ok, will do.
– Jasha
Apr 28 at 17:08
add a comment |
5
:h v:shell_error
– Christian Brabandt
Apr 28 at 16:43
@ChristianBrabandt Thanks, that works.
– Jasha
Apr 28 at 16:57
@Jasha consider self-answering if youve got it figured out now
– D. Ben Knoble
Apr 28 at 17:06
@D.BenKnoble Ok, will do.
– Jasha
Apr 28 at 17:08
5
5
:h v:shell_error– Christian Brabandt
Apr 28 at 16:43
:h v:shell_error– Christian Brabandt
Apr 28 at 16:43
@ChristianBrabandt Thanks, that works.
– Jasha
Apr 28 at 16:57
@ChristianBrabandt Thanks, that works.
– Jasha
Apr 28 at 16:57
@Jasha consider self-answering if youve got it figured out now
– D. Ben Knoble
Apr 28 at 17:06
@Jasha consider self-answering if youve got it figured out now
– D. Ben Knoble
Apr 28 at 17:06
@D.BenKnoble Ok, will do.
– Jasha
Apr 28 at 17:08
@D.BenKnoble Ok, will do.
– Jasha
Apr 28 at 17:08
add a comment |
1 Answer
1
active
oldest
votes
Mentioned in the comments above, the v:shell_error variable gives the result of the last shell command. So the exit status can be tested as follows:
let output = system("my_shell_command")
if v:shell_error != 0
echo output
endif
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "599"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f19773%2fget-exit-status-from-system-call%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Mentioned in the comments above, the v:shell_error variable gives the result of the last shell command. So the exit status can be tested as follows:
let output = system("my_shell_command")
if v:shell_error != 0
echo output
endif
add a comment |
Mentioned in the comments above, the v:shell_error variable gives the result of the last shell command. So the exit status can be tested as follows:
let output = system("my_shell_command")
if v:shell_error != 0
echo output
endif
add a comment |
Mentioned in the comments above, the v:shell_error variable gives the result of the last shell command. So the exit status can be tested as follows:
let output = system("my_shell_command")
if v:shell_error != 0
echo output
endif
Mentioned in the comments above, the v:shell_error variable gives the result of the last shell command. So the exit status can be tested as follows:
let output = system("my_shell_command")
if v:shell_error != 0
echo output
endif
answered Apr 28 at 17:33
JashaJasha
1655
1655
add a comment |
add a comment |
Thanks for contributing an answer to Vi and Vim Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f19773%2fget-exit-status-from-system-call%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
5
:h v:shell_error– Christian Brabandt
Apr 28 at 16:43
@ChristianBrabandt Thanks, that works.
– Jasha
Apr 28 at 16:57
@Jasha consider self-answering if youve got it figured out now
– D. Ben Knoble
Apr 28 at 17:06
@D.BenKnoble Ok, will do.
– Jasha
Apr 28 at 17:08