0

Dear fellow developers,

I'm repeatedly using (and developing) a python script for calculations, by executing it through the windows command prompt in each test.

The script has some parsed options.

In order to make each of my calculations easily reproducible, I save the actual command I entered to execute each calculation. For the moment I simply copy by hand the command once I executed it and I put it in a file. But since I have to do it for each calculation, I wonder is there is any python script line that could take my command line input, like:

python script.py --option="foo" 

into a file.

The form of the command could be:

%save file=_command_used.txt% python script.py --option=foo

which would create the file and save the actual command "python script.py --option=foo" into it.

Thanks in advance! Best regards!

I would love to have solutions for both Windows command prompt and Linux shell command prompt.

Glxblt76
  • 365
  • 5
  • 14
  • The post is a bit confusing, I ask a python script command but I exemplify with and actual command-line modification. In fact both solutions would help. – Glxblt76 Feb 03 '17 at 07:31

2 Answers2

0

On Linux there is the script command that will capture all entered commands in a file. Use it like that:

script -a _command_used.txt
python script.py --option=foo
python script.py --option=bar

The -a option stands for append so the _command_used.txt will not be overwritten.

On Windows you can achieve a similar thing using Start-Transcript and Stop-Transcript cmdlet. See this related post.

Community
  • 1
  • 1
0

Since you are using Python, I recommend you investigate the Xonsh shell as one way to solve this. It is cross platform and is scripted with python.

Community
  • 1
  • 1
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135