Launch and kill a program in script and continue [duplicate]Bash ignoring error for a particular commandGet the source directory of a Bash script from within the script itselfHow do I prompt for Yes/No/Cancel input in a Linux shell script?How to check if a program exists from a Bash script?What killed my process and why?YYYY-MM-DD format date in shell scriptFind (and kill) process locking port 3000 on MacHow do I run a node.js app as a background service?Check existence of input argument in a Bash shell scriptKilling a script launched in a Process via os.system()Xcode process launch failed: Security

How can a function with a hole (removable discontinuity) equal a function with no hole?

How to draw lines on a tikz-cd diagram

How to be diplomatic in refusing to write code that breaches the privacy of our users

What is the best translation for "slot" in the context of multiplayer video games?

Failed to fetch jessie backports repository

Proof of work - lottery approach

What is the intuitive meaning of having a linear relationship between the logs of two variables?

System.debug(JSON.Serialize(o)) Not longer shows full string

How to run a prison with the smallest amount of guards?

Gears on left are inverse to gears on right?

Is exact Kanji stroke length important?

How do I find the solutions of the following equation?

Do the temporary hit points from Reckless Abandon stack if I make multiple attacks on my turn?

Applicability of Single Responsibility Principle

Method to test if a number is a perfect power?

Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?

What can we do to stop prior company from asking us questions?

How does Loki do this?

Short story about space worker geeks who zone out by 'listening' to radiation from stars

Two monoidal structures and copowering

How easy is it to start Magic from scratch?

How did Arya survive the stabbing?

Is the destination of a commercial flight important for the pilot?

What happens if you roll doubles 3 times then land on "Go to jail?"



Launch and kill a program in script and continue [duplicate]


Bash ignoring error for a particular commandGet the source directory of a Bash script from within the script itselfHow do I prompt for Yes/No/Cancel input in a Linux shell script?How to check if a program exists from a Bash script?What killed my process and why?YYYY-MM-DD format date in shell scriptFind (and kill) process locking port 3000 on MacHow do I run a node.js app as a background service?Check existence of input argument in a Bash shell scriptKilling a script launched in a Process via os.system()Xcode process launch failed: Security













1
















This question already has an answer here:



  • Bash ignoring error for a particular command

    6 answers



I have a script that needs to launch a program in order for the program to create and populate some folders. The program only needs to run briefly and then close, before the script continues.



However when the program is killed, the script does not continue. How can I do this?



printf "before"

(timeout -sHUP 3s firefox)

printf "after"


I thought I was launching the program in a subshell but i am not sure if this is the case.










share|improve this question













marked as duplicate by John Kugelman bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 9 at 16:00


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • 1





    timeout returns an non-zero exit status when it kills the program that it runs. If set -e (or, equivalently, set -o errexit) is in effect when that happens, the script will stop immediately and silently. The parentheses ((...)) ensure that the program is run in a subshell. That doesn't change the effect of the errexit setting, and it's not clear why a subshell is being used here.

    – pjh
    Mar 8 at 19:04












  • I had set -o errexit set indeed. Any way to ignore the timeout error specifically but keep errexit?

    – myol
    Mar 9 at 15:13















1
















This question already has an answer here:



  • Bash ignoring error for a particular command

    6 answers



I have a script that needs to launch a program in order for the program to create and populate some folders. The program only needs to run briefly and then close, before the script continues.



However when the program is killed, the script does not continue. How can I do this?



printf "before"

(timeout -sHUP 3s firefox)

printf "after"


I thought I was launching the program in a subshell but i am not sure if this is the case.










share|improve this question













marked as duplicate by John Kugelman bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 9 at 16:00


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • 1





    timeout returns an non-zero exit status when it kills the program that it runs. If set -e (or, equivalently, set -o errexit) is in effect when that happens, the script will stop immediately and silently. The parentheses ((...)) ensure that the program is run in a subshell. That doesn't change the effect of the errexit setting, and it's not clear why a subshell is being used here.

    – pjh
    Mar 8 at 19:04












  • I had set -o errexit set indeed. Any way to ignore the timeout error specifically but keep errexit?

    – myol
    Mar 9 at 15:13













1












1








1









This question already has an answer here:



  • Bash ignoring error for a particular command

    6 answers



I have a script that needs to launch a program in order for the program to create and populate some folders. The program only needs to run briefly and then close, before the script continues.



However when the program is killed, the script does not continue. How can I do this?



printf "before"

(timeout -sHUP 3s firefox)

printf "after"


I thought I was launching the program in a subshell but i am not sure if this is the case.










share|improve this question















This question already has an answer here:



  • Bash ignoring error for a particular command

    6 answers



I have a script that needs to launch a program in order for the program to create and populate some folders. The program only needs to run briefly and then close, before the script continues.



However when the program is killed, the script does not continue. How can I do this?



printf "before"

(timeout -sHUP 3s firefox)

printf "after"


I thought I was launching the program in a subshell but i am not sure if this is the case.





This question already has an answer here:



  • Bash ignoring error for a particular command

    6 answers







bash process






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 11:07









myolmyol

1,94374077




1,94374077




marked as duplicate by John Kugelman bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 9 at 16:00


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by John Kugelman bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 9 at 16:00


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









  • 1





    timeout returns an non-zero exit status when it kills the program that it runs. If set -e (or, equivalently, set -o errexit) is in effect when that happens, the script will stop immediately and silently. The parentheses ((...)) ensure that the program is run in a subshell. That doesn't change the effect of the errexit setting, and it's not clear why a subshell is being used here.

    – pjh
    Mar 8 at 19:04












  • I had set -o errexit set indeed. Any way to ignore the timeout error specifically but keep errexit?

    – myol
    Mar 9 at 15:13












  • 1





    timeout returns an non-zero exit status when it kills the program that it runs. If set -e (or, equivalently, set -o errexit) is in effect when that happens, the script will stop immediately and silently. The parentheses ((...)) ensure that the program is run in a subshell. That doesn't change the effect of the errexit setting, and it's not clear why a subshell is being used here.

    – pjh
    Mar 8 at 19:04












  • I had set -o errexit set indeed. Any way to ignore the timeout error specifically but keep errexit?

    – myol
    Mar 9 at 15:13







1




1





timeout returns an non-zero exit status when it kills the program that it runs. If set -e (or, equivalently, set -o errexit) is in effect when that happens, the script will stop immediately and silently. The parentheses ((...)) ensure that the program is run in a subshell. That doesn't change the effect of the errexit setting, and it's not clear why a subshell is being used here.

– pjh
Mar 8 at 19:04






timeout returns an non-zero exit status when it kills the program that it runs. If set -e (or, equivalently, set -o errexit) is in effect when that happens, the script will stop immediately and silently. The parentheses ((...)) ensure that the program is run in a subshell. That doesn't change the effect of the errexit setting, and it's not clear why a subshell is being used here.

– pjh
Mar 8 at 19:04














I had set -o errexit set indeed. Any way to ignore the timeout error specifically but keep errexit?

– myol
Mar 9 at 15:13





I had set -o errexit set indeed. Any way to ignore the timeout error specifically but keep errexit?

– myol
Mar 9 at 15:13












2 Answers
2






active

oldest

votes


















1














I solved this with a hacky work around.



set -o errexit

printf "before"

timeout -sHUP 3s firefox || true

printf "after"


The alternative cleaner method would be



set -o errexit

printf "before"

set +e
timeout -sHUP 3s firefox
set -e

printf "after"





share|improve this answer























  • It's not a hack at all. Appending || : is a common idiom to suppress the exit code of a failing command when you don't care.

    – John Kugelman
    Mar 9 at 15:59


















0














printf takes 2 arguments - a FORMAT string, then an ARGUMENT (i.e the text to be outputted).



When you call printf "before" you are actually passing a format string with no argument, which is not displayed properly.



The easiest fix is to instead use echo:



echo "before"
timeout -sHUP 3s firefox
echo "after"


Or if you need formatting, to instead do e.g.:



printf "%sn" "before"
timeout -sHUP 3s firefox
printf "%sn" "after"





share|improve this answer


















  • 3





    Addendum - printf will work fine with one argument - he just didn't include a newline, which unlike echo it doesn't add by default. printf "beforen"

    – Paul Hodges
    Mar 8 at 14:53











  • stdout was just to make the example concise for stack overflow, the program has various other method calls and bash commands that get ignored after timeout. The issue seems to be in the use of set -o errexit

    – myol
    Mar 9 at 15:15

















2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I solved this with a hacky work around.



set -o errexit

printf "before"

timeout -sHUP 3s firefox || true

printf "after"


The alternative cleaner method would be



set -o errexit

printf "before"

set +e
timeout -sHUP 3s firefox
set -e

printf "after"





share|improve this answer























  • It's not a hack at all. Appending || : is a common idiom to suppress the exit code of a failing command when you don't care.

    – John Kugelman
    Mar 9 at 15:59















1














I solved this with a hacky work around.



set -o errexit

printf "before"

timeout -sHUP 3s firefox || true

printf "after"


The alternative cleaner method would be



set -o errexit

printf "before"

set +e
timeout -sHUP 3s firefox
set -e

printf "after"





share|improve this answer























  • It's not a hack at all. Appending || : is a common idiom to suppress the exit code of a failing command when you don't care.

    – John Kugelman
    Mar 9 at 15:59













1












1








1







I solved this with a hacky work around.



set -o errexit

printf "before"

timeout -sHUP 3s firefox || true

printf "after"


The alternative cleaner method would be



set -o errexit

printf "before"

set +e
timeout -sHUP 3s firefox
set -e

printf "after"





share|improve this answer













I solved this with a hacky work around.



set -o errexit

printf "before"

timeout -sHUP 3s firefox || true

printf "after"


The alternative cleaner method would be



set -o errexit

printf "before"

set +e
timeout -sHUP 3s firefox
set -e

printf "after"






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 9 at 15:39









myolmyol

1,94374077




1,94374077












  • It's not a hack at all. Appending || : is a common idiom to suppress the exit code of a failing command when you don't care.

    – John Kugelman
    Mar 9 at 15:59

















  • It's not a hack at all. Appending || : is a common idiom to suppress the exit code of a failing command when you don't care.

    – John Kugelman
    Mar 9 at 15:59
















It's not a hack at all. Appending || : is a common idiom to suppress the exit code of a failing command when you don't care.

– John Kugelman
Mar 9 at 15:59





It's not a hack at all. Appending || : is a common idiom to suppress the exit code of a failing command when you don't care.

– John Kugelman
Mar 9 at 15:59













0














printf takes 2 arguments - a FORMAT string, then an ARGUMENT (i.e the text to be outputted).



When you call printf "before" you are actually passing a format string with no argument, which is not displayed properly.



The easiest fix is to instead use echo:



echo "before"
timeout -sHUP 3s firefox
echo "after"


Or if you need formatting, to instead do e.g.:



printf "%sn" "before"
timeout -sHUP 3s firefox
printf "%sn" "after"





share|improve this answer


















  • 3





    Addendum - printf will work fine with one argument - he just didn't include a newline, which unlike echo it doesn't add by default. printf "beforen"

    – Paul Hodges
    Mar 8 at 14:53











  • stdout was just to make the example concise for stack overflow, the program has various other method calls and bash commands that get ignored after timeout. The issue seems to be in the use of set -o errexit

    – myol
    Mar 9 at 15:15















0














printf takes 2 arguments - a FORMAT string, then an ARGUMENT (i.e the text to be outputted).



When you call printf "before" you are actually passing a format string with no argument, which is not displayed properly.



The easiest fix is to instead use echo:



echo "before"
timeout -sHUP 3s firefox
echo "after"


Or if you need formatting, to instead do e.g.:



printf "%sn" "before"
timeout -sHUP 3s firefox
printf "%sn" "after"





share|improve this answer


















  • 3





    Addendum - printf will work fine with one argument - he just didn't include a newline, which unlike echo it doesn't add by default. printf "beforen"

    – Paul Hodges
    Mar 8 at 14:53











  • stdout was just to make the example concise for stack overflow, the program has various other method calls and bash commands that get ignored after timeout. The issue seems to be in the use of set -o errexit

    – myol
    Mar 9 at 15:15













0












0








0







printf takes 2 arguments - a FORMAT string, then an ARGUMENT (i.e the text to be outputted).



When you call printf "before" you are actually passing a format string with no argument, which is not displayed properly.



The easiest fix is to instead use echo:



echo "before"
timeout -sHUP 3s firefox
echo "after"


Or if you need formatting, to instead do e.g.:



printf "%sn" "before"
timeout -sHUP 3s firefox
printf "%sn" "after"





share|improve this answer













printf takes 2 arguments - a FORMAT string, then an ARGUMENT (i.e the text to be outputted).



When you call printf "before" you are actually passing a format string with no argument, which is not displayed properly.



The easiest fix is to instead use echo:



echo "before"
timeout -sHUP 3s firefox
echo "after"


Or if you need formatting, to instead do e.g.:



printf "%sn" "before"
timeout -sHUP 3s firefox
printf "%sn" "after"






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 8 at 11:25









matchmatch

3,1131925




3,1131925







  • 3





    Addendum - printf will work fine with one argument - he just didn't include a newline, which unlike echo it doesn't add by default. printf "beforen"

    – Paul Hodges
    Mar 8 at 14:53











  • stdout was just to make the example concise for stack overflow, the program has various other method calls and bash commands that get ignored after timeout. The issue seems to be in the use of set -o errexit

    – myol
    Mar 9 at 15:15












  • 3





    Addendum - printf will work fine with one argument - he just didn't include a newline, which unlike echo it doesn't add by default. printf "beforen"

    – Paul Hodges
    Mar 8 at 14:53











  • stdout was just to make the example concise for stack overflow, the program has various other method calls and bash commands that get ignored after timeout. The issue seems to be in the use of set -o errexit

    – myol
    Mar 9 at 15:15







3




3





Addendum - printf will work fine with one argument - he just didn't include a newline, which unlike echo it doesn't add by default. printf "beforen"

– Paul Hodges
Mar 8 at 14:53





Addendum - printf will work fine with one argument - he just didn't include a newline, which unlike echo it doesn't add by default. printf "beforen"

– Paul Hodges
Mar 8 at 14:53













stdout was just to make the example concise for stack overflow, the program has various other method calls and bash commands that get ignored after timeout. The issue seems to be in the use of set -o errexit

– myol
Mar 9 at 15:15





stdout was just to make the example concise for stack overflow, the program has various other method calls and bash commands that get ignored after timeout. The issue seems to be in the use of set -o errexit

– myol
Mar 9 at 15:15



Popular posts from this blog

How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229