Using python to start programs after logging in
python at mrabarnett.plus.com
Thu Jan 19 15:12:30 EST 2017
On 2017-01-19 19:08, Cecil Westerhof wrote:
> I am writing a python program to start the programs that need to be
> started after logging in.
> I have the following imports:
> from subprocess import check_call, Popen, STDOUT
> from time import sleep, strftime
> And use the following code:
> check_call(tuple('wmctrl -s 10'.split()))
> log_file = open('Logging/firefox_%T.log'.replace('%T', strftime('%F_%R')), 'w')
> Popen(tuple('firefox'.split()), stdout = log_file, stderr = STDOUT)
> The first statement is to go to the correct desktop.
> Is this a good way to do things, or could I do it in a better way?
Apart from the other answer, your use of .replace is odd. This would be
log_file = open('Logging/firefox_%s.log' % strftime('%F_%R'), 'w')
Even better would be to use the 'with' statement as well.
More information about the Python-list