W
W
WhiteApfel2018-11-27 16:11:12
linux
WhiteApfel, 2018-11-27 16:11:12

Is it possible to make a script that will run program.py in a terminal?

It is required to write a script that would run client/main.py through the terminal.
On Windows, I implemented this via a bat file:

@echo off
python client/main.py

In this case, the command line would run and output what python was outputting
. On Linux, I saw the solution in .sh:
# !/bin/bash
python3 client/main.py

But there is no output.
I know very little about bash scripts, please do not throw slippers.
I tried to do this:
# !/bin/bash
konsole -e python3 client/main.py

The terminal opens and closes when completed. And it only works in kde, because it's konsole, not *terminal*
Requires double-click launch, not terminal

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
planc, 2018-11-27
@WhiteApfel

if you have a desktop installed, then there should be default applications through xdg
for the terminal - this is x-terminal-emulator
https://askubuntu.com/questions/46627/how-can-i-ma...
if not, then you can just hardcode all terminals and iterate

#!/bin/bash                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                              
for i in konsole urxvt gnome-terminal xterm sc                                                                                                                                                                                                
do                                                                                                                                                                                                                                            
    FULL_PATH=`which $i 2>/dev/null`                                                                                                                                                                                                          
    if                                                                                                                                                                                                                     
    then                                                                                                                                                                                                                                      
        echo 'первый попавшийся терминал:' $FULL_PATH                                                                                                                                                                                         
        break                                                                                                                                                                                                                                 
    fi                                                                                                                                                                                                                                        
done

L
latush, 2018-11-27
@latush

># !/bin/bash
remove the space between # and !
and try the first option again

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question