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

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page