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
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.
bash process
marked as duplicate by John Kugelman
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.
add a comment |
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.
bash process
marked as duplicate by John Kugelman
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
timeoutreturns an non-zero exit status when it kills the program that it runs. Ifset -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 theerrexitsetting, and it's not clear why a subshell is being used here.
– pjh
Mar 8 at 19:04
I hadset -o errexitset indeed. Any way to ignore the timeout error specifically but keeperrexit?
– myol
Mar 9 at 15:13
add a comment |
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.
bash process
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
bash process
asked Mar 8 at 11:07
myolmyol
1,94374077
1,94374077
marked as duplicate by John Kugelman
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
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
timeoutreturns an non-zero exit status when it kills the program that it runs. Ifset -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 theerrexitsetting, and it's not clear why a subshell is being used here.
– pjh
Mar 8 at 19:04
I hadset -o errexitset indeed. Any way to ignore the timeout error specifically but keeperrexit?
– myol
Mar 9 at 15:13
add a comment |
1
timeoutreturns an non-zero exit status when it kills the program that it runs. Ifset -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 theerrexitsetting, and it's not clear why a subshell is being used here.
– pjh
Mar 8 at 19:04
I hadset -o errexitset indeed. Any way to ignore the timeout error specifically but keeperrexit?
– 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
add a comment |
2 Answers
2
active
oldest
votes
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"
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
add a comment |
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"
3
Addendum -printfwill work fine with one argument - he just didn't include a newline, which unlikeechoit 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 aftertimeout. The issue seems to be in the use ofset -o errexit
– myol
Mar 9 at 15:15
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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"
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
add a comment |
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"
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
add a comment |
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"
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"
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
add a comment |
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
add a comment |
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"
3
Addendum -printfwill work fine with one argument - he just didn't include a newline, which unlikeechoit 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 aftertimeout. The issue seems to be in the use ofset -o errexit
– myol
Mar 9 at 15:15
add a comment |
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"
3
Addendum -printfwill work fine with one argument - he just didn't include a newline, which unlikeechoit 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 aftertimeout. The issue seems to be in the use ofset -o errexit
– myol
Mar 9 at 15:15
add a comment |
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"
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"
answered Mar 8 at 11:25
matchmatch
3,1131925
3,1131925
3
Addendum -printfwill work fine with one argument - he just didn't include a newline, which unlikeechoit 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 aftertimeout. The issue seems to be in the use ofset -o errexit
– myol
Mar 9 at 15:15
add a comment |
3
Addendum -printfwill work fine with one argument - he just didn't include a newline, which unlikeechoit 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 aftertimeout. The issue seems to be in the use ofset -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
add a comment |
1
timeoutreturns an non-zero exit status when it kills the program that it runs. Ifset -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 theerrexitsetting, and it's not clear why a subshell is being used here.– pjh
Mar 8 at 19:04
I had
set -o errexitset indeed. Any way to ignore the timeout error specifically but keeperrexit?– myol
Mar 9 at 15:13