0

I need to write a scirpt in python (or bash) which:

  • open a new linux terminal with a few tabs
  • do a 'source myfile.csh' command on each of the tab

I've tried with something like this:

 os.system("gnome-terminal --tab --working-directory=/repo/ -e 'source myfile.csh' ")

but it didn't work (for example file was not found even though I was in a correct directory or can't open a .csh file blah blah blah)

I've also tried a few other options, but I didn't find a proper soultion for my problem.

I don't know why I can't do a simple "open a new terminal, write a command and execute it"

Maybe is there any simple solution WITHOUT installing any new software (I don't have a root)?

Legut
  • 1
  • 1
  • Any error message when doing the shown command? – languitar Mar 02 '17 at 09:07
  • does this command work when pasting in a terminal? – Jean-François Fabre Mar 02 '17 at 09:08
  • "There was an error creating the child process for this terminal Failed to execute child process "source" (No such file or directory)" @languitar – Legut Mar 02 '17 at 09:10
  • Masquerading this as a Python question is extremely obscure. If you can pull it off from the command line, you can then run it from Python (or Ruby, or C, or ...) – tripleee Mar 02 '17 at 09:30
  • @tripleee You marked my question as duplicate but the topic proposed by you as an answer didn't solve my problem at all. I also removed the python tag – Legut Mar 02 '17 at 09:52
  • What is the precise problem you are trying to solve here? Not realizing you have to run `tcsh` or `csh` in order for `source` to work seems like a good guess as to how to reduce the problem to a [MCVE](/help/mcve) and any remaining roblem seems like a tangential `csh`-only problem which should probably be a new question. If you can clarify your question to rescope it to a simpler problem with a single straightforward answer, I'll be happy to lift the duplicate flag (though it seems somewhat likely that it will then be a duplicate of another existing question). – tripleee Mar 02 '17 at 12:23
  • If your shell is `tcsh` then in no event is this a [tag:bash] question either, but I'm hesitant to remove the tag before we know what exactly would help you accomplish what you need. The "error: must source" looks like an error from the script itself, but it's completely obscure why this is a requirement in the first place. – tripleee Mar 02 '17 at 12:25

1 Answers1

2

-e will execute a process. However source is an instruction of your shell. What you need to do is to call your shell with -e and pass arguments to the shell in order to execute the source instruction. Should be something like

os.system("gnome-terminal --tab --working-directory=/repo/ -e 'tcsh -c \"source myfile.csh\"'")
languitar
  • 6,554
  • 2
  • 37
  • 62