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?













2















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.










share|improve this question

















  • 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















2















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.










share|improve this question

















  • 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













2












2








2








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.










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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












  • 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










1 Answer
1






active

oldest

votes


















3














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





share|improve this answer























    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
    );



    );













    draft saved

    draft discarded


















    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









    3














    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





    share|improve this answer



























      3














      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





      share|improve this answer

























        3












        3








        3







        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





        share|improve this answer













        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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 28 at 17:33









        JashaJasha

        1655




        1655



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

            Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

            Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림