LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-31-2021, 01:46 PM   #1
Arch4GoodieLike
Member
 
Registered: Sep 2020
Location: Cave
Distribution: Arch Linux
Posts: 143

Rep: Reputation: Disabled
Question 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.

Last edited by Arch4GoodieLike; 10-31-2021 at 02:19 PM.
 
Old 10-31-2021, 01:50 PM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
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.

Last edited by shruggy; 10-31-2021 at 02:01 PM.
 
Old 10-31-2021, 01:52 PM   #3
Arch4GoodieLike
Member
 
Registered: Sep 2020
Location: Cave
Distribution: Arch Linux
Posts: 143

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shruggy View Post
Remove ; bash
doesn't make a difference.
 
Old 10-31-2021, 01:55 PM   #4
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
I amended my post. See above.
 
Old 10-31-2021, 02:01 PM   #5
Arch4GoodieLike
Member
 
Registered: Sep 2020
Location: Cave
Distribution: Arch Linux
Posts: 143

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shruggy View Post
I amended my post. See above.
It only troubles the script and has nothing to do with what I'm seeking for.
 
Old 10-31-2021, 02:03 PM   #6
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Then I don't understand what you're seeking for.
 
Old 10-31-2021, 02:06 PM   #7
Arch4GoodieLike
Member
 
Registered: Sep 2020
Location: Cave
Distribution: Arch Linux
Posts: 143

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shruggy View Post
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.

Last edited by Arch4GoodieLike; 10-31-2021 at 02:14 PM.
 
Old 10-31-2021, 02:27 PM   #8
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
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.

Last edited by shruggy; 10-31-2021 at 02:29 PM.
 
Old 10-31-2021, 02:42 PM   #9
Arch4GoodieLike
Member
 
Registered: Sep 2020
Location: Cave
Distribution: Arch Linux
Posts: 143

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shruggy View Post
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?
 
Old 10-31-2021, 02:51 PM   #10
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Quote:
Originally Posted by Arch4GoodieLike View Post
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 View Post
with what do I have to replace 'junk' with?
Doesn't matter. This variable gets discarded anyway.
 
Old 10-31-2021, 03:01 PM   #11
Arch4GoodieLike
Member
 
Registered: Sep 2020
Location: Cave
Distribution: Arch Linux
Posts: 143

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shruggy View Post
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 !

Last edited by Arch4GoodieLike; 10-31-2021 at 03:06 PM.
 
Old 10-31-2021, 06:12 PM   #12
enigma9o7
Senior Member
 
Registered: Jul 2018
Location: Silicon Valley
Distribution: Bodhi Linux
Posts: 1,388

Rep: Reputation: 560Reputation: 560Reputation: 560Reputation: 560Reputation: 560Reputation: 560
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
 
1 members found this post helpful.
  


Reply

Tags
bash, python, shell



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get first day of last month and last day of last month in bash xowl Linux - Software 18 02-09-2017 09:49 AM
How to make a linux desktop step by step ? 915086731 Linux - General 5 03-23-2011 07:08 AM
Step by Step way to make SUSE 9.3 VMWARE ready ?? my-unix-dream Linux - Newbie 5 07-05-2005 09:18 PM
Step-by-step procedure to make a Live CD? kRu_ZaDeR Linux - General 3 03-28-2003 09:34 PM
Any1 please make a step by step install of RH7.1 Simsala Linux - Software 5 08-17-2001 06:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration