LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   last step to make script fully work (https://www.linuxquestions.org/questions/programming-9/last-step-to-make-script-fully-work-4175702904/)

Arch4GoodieLike 10-31-2021 01:46 PM

last step to make script fully work
 
Code:

#!/bin/bash -e

#path to select.sh
SelectPath="~/startup-script/"

# Run game.py
gnome-terminal -- sh -c "python3 game.py; bash"

# Wait until the terminal's child exist
wait
 exec "${SelectPath}"./script.sh

only thing left to include now is to make the gnome-terminal that launched the game to close once the game is closed.

shruggy 10-31-2021 01:50 PM

Remove ; bash

Actually, most terminal emulators including gnome-terminal have option -e. So you could just
Code:

gnome-terminal -e python3 game.py
Well, I'm getting scolded by gnome-terminal:
Code:

# Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
# Use “-- ” to terminate the options and put the command line to execute after it.

So
Code:

gnome-terminal -- python3 game.py
is it then.

Arch4GoodieLike 10-31-2021 01:52 PM

Quote:

Originally Posted by shruggy (Post 6297345)
Remove ; bash

doesn't make a difference.

shruggy 10-31-2021 01:55 PM

I amended my post. See above.

Arch4GoodieLike 10-31-2021 02:01 PM

Quote:

Originally Posted by shruggy (Post 6297348)
I amended my post. See above.

It only troubles the script and has nothing to do with what I'm seeking for.

shruggy 10-31-2021 02:03 PM

Then I don't understand what you're seeking for.

Arch4GoodieLike 10-31-2021 02:06 PM

Quote:

Originally Posted by shruggy (Post 6297350)
Then I don't understand what you're seeking for.

this
Quote:

only thing left to include now is to make the gnome-terminal that launched the game to close once the game is closed.
Figuratively spoken, once I quit the game.py which closes the game, I want the terminal's child being closed as well.

in other words, once game.py no longer is in use, which means closed, I want the terminal's child (which is the terminal) to be closed.

shruggy 10-31-2021 02:27 PM

Try this
Code:

gnome-terminal -- read -p 'Hit Enter ' junk
and you'll see that the terminal window is closed as soon as you hit Enter. So I guess the problem is with the game that doesn't get properly closed.

Arch4GoodieLike 10-31-2021 02:42 PM

Quote:

Originally Posted by shruggy (Post 6297358)
Try this
Code:

gnome-terminal -- read -p 'Hit Enter ' junk
and you'll see that the terminal window is closed as soon as you hit Enter. So I guess the problem is with the game that doesn't get properly closed.

I get this
Code:

# Error: Failed to execute child process “read”: Failed to execve: No such file or directory
and btw, with what do I have to replace 'junk' with?

shruggy 10-31-2021 02:51 PM

Quote:

Originally Posted by Arch4GoodieLike (Post 6297361)
I get this
Code:

# Error: Failed to execute child process “read”: Failed to execve: No such file or directory

Strange. And if you wrap it in a shell call?
Code:

gnome-terminal -- sh -c 'read -p "Hit Enter " _'
Quote:

Originally Posted by Arch4GoodieLike (Post 6297361)
with what do I have to replace 'junk' with?

Doesn't matter. This variable gets discarded anyway.

Arch4GoodieLike 10-31-2021 03:01 PM

Quote:

Originally Posted by shruggy (Post 6297363)
Strange. And if you wrap it in a shell call?
Code:

gnome-terminal -- sh -c 'read -p "Hit Enter " _'

Doesn't matter. This variable gets discarded anyway.

Thanks, using
Code:

gnome-terminal -- sh -c "python3 game.py" 'read -p "Hit Enter " _'
exits the child process without even needing to hit enter :)!

enigma9o7 10-31-2021 06:12 PM

Its unclear what you're trying to do, and why you're calling bash and gnome-terminal from a shell script in the first place. But seems to me you should just add

"python3 game.py" to the second line of "script.sh" and be done with it.

Otherise I'd try...
Code:

#!/bin/bash
python3 game.py
source $HOME/startup-script/script.sh



All times are GMT -5. The time now is 08:49 AM.