473,382 Members | 1,524 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Command-line does work when scheduled

Jim
Hi,

I want to schedule a Python program that reads the command line for
input. However, when adding an argument to the command line Python
will not pick it up when using Windows scheduled tasks.

How do I get it to work?

Thanks,
Jim

Sep 29 '07 #1
11 3359
En Sat, 29 Sep 2007 17:34:34 -0300, Jim <js******@compuserve.comescribi�:
I want to schedule a Python program that reads the command line for
input. However, when adding an argument to the command line Python
will not pick it up when using Windows scheduled tasks.

How do I get it to work?
Do you write the command line when defining the task? Using double quotes
around arguments with spaces?
It works fine for me.

--
Gabriel Genellina

Sep 29 '07 #2
Jim
On Sep 29, 3:19 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Sat, 29 Sep 2007 17:34:34 -0300, Jim <jscre...@compuserve.comescribi?:
I want to schedule a Python program that reads the command line for
input. However, when adding an argument to the command line Python
will not pick it up when using Windows scheduled tasks.
How do I get it to work?

Do you write the command line when defining the task? Using double quotes
around arguments with spaces?
It works fine for me.

--
Gabriel Genellina
I ran the following on the Scheduled Tasks:
"J:\Jim Crerar\MyPython\Zero_OE_Counter\Zero_OE_Counter.py " n
"J:\Jim Crerar\MyPython\Zero_OE_Counter\Zero_OE_Counter.py n"
"J:\Jim Crerar\MyPython\Zero_OE_Counter\Zero_OE_Counter.py " "n"
None of them work.
However, no problem with running from *.bat file or directly from
shortcut on my Desktop.
Thanks,
Jim

Sep 29 '07 #3
En Sat, 29 Sep 2007 19:17:49 -0300, Jim <js******@compuserve.comescribi�:
On Sep 29, 3:19 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
>En Sat, 29 Sep 2007 17:34:34 -0300, Jim <jscre...@compuserve.com>
escribi?:
I want to schedule a Python program that reads the command line for
input. However, when adding an argument to the command line Python
will not pick it up when using Windows scheduled tasks.
How do I get it to work?

Do you write the command line when defining the task? Using double
quotes
around arguments with spaces?
It works fine for me.
I ran the following on the Scheduled Tasks:
"J:\Jim Crerar\MyPython\Zero_OE_Counter\Zero_OE_Counter.py " n
"J:\Jim Crerar\MyPython\Zero_OE_Counter\Zero_OE_Counter.py n"
"J:\Jim Crerar\MyPython\Zero_OE_Counter\Zero_OE_Counter.py " "n"
None of them work.
However, no problem with running from *.bat file or directly from
shortcut on my Desktop.
Try prepending the Python executable:

C:\Python25\Python.exe "J:\Jim
Crerar\MyPython\Zero_OE_Counter\Zero_OE_Counter.py " n

If it works this way, maybe the .py file extension is not correctly
registered.

--
Gabriel Genellina

Sep 30 '07 #4
Jim
On Sep 29, 6:56 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Sat, 29 Sep 2007 19:17:49 -0300, Jim <jscre...@compuserve.comescribi?:


On Sep 29, 3:19 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Sat, 29 Sep 2007 17:34:34 -0300, Jim <jscre...@compuserve.com>
escribi?:
I want to schedule a Python program that reads the command line for
input. However, when adding an argument to the command line Python
will not pick it up when using Windows scheduled tasks.
How do I get it to work?
Do you write the command line when defining the task? Using double
quotes
around arguments with spaces?
It works fine for me.
I ran the following on the Scheduled Tasks:
"J:\Jim Crerar\MyPython\Zero_OE_Counter\Zero_OE_Counter.py " n
"J:\Jim Crerar\MyPython\Zero_OE_Counter\Zero_OE_Counter.py n"
"J:\Jim Crerar\MyPython\Zero_OE_Counter\Zero_OE_Counter.py " "n"
None of them work.
However, no problem with running from *.bat file or directly from
shortcut on my Desktop.

Try prepending the Python executable:

C:\Python25\Python.exe "J:\Jim
Crerar\MyPython\Zero_OE_Counter\Zero_OE_Counter.py " n

If it works this way, maybe the .py file extension is not correctly
registered.

--
Gabriel Genellina- Hide quoted text -

- Show quoted text -
Yes, it works this way.
How do I register the .py extension correctly?

Thanks,
Jim

Sep 30 '07 #5
En Sat, 29 Sep 2007 22:04:06 -0300, Jim <js******@compuserve.comescribi�:
>If it works this way, maybe the .py file extension is not correctly
registered.

Yes, it works this way.
How do I register the .py extension correctly?
From a command line, type:
assoc .py
You should get:
..py=Python.File
If you get an error, or another thing like py_auto_file:
assoc .py=Python.File

Then:
ftype Python.File
You should get:
Python.File=c:\path\to\python.exe "%1" %*
If you don't:
ftype Python.File=c:\path\to\python.exe "%1" %*

The %* at the end is important: if you created the association by using
"Open with...", or selecting Python from the list of installed programs,
very likely the command says only "%1" - that is, the script being open,
but without any additional arguments.

Better if you have administrative rights to do this tasks.

--
Gabriel Genellina

Sep 30 '07 #6
Jim
On Sep 29, 8:45 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Sat, 29 Sep 2007 22:04:06 -0300, Jim <jscre...@compuserve.comescribi?:
If it works this way, maybe the .py file extension is not correctly
registered.
Yes, it works this way.
How do I register the .py extension correctly?

From a command line, type:
assoc .py
You should get:
.py=Python.File
If you get an error, or another thing like py_auto_file:
assoc .py=Python.File

Then:
ftype Python.File
You should get:
Python.File=c:\path\to\python.exe "%1" %*
If you don't:
ftype Python.File=c:\path\to\python.exe "%1" %*

The %* at the end is important: if you created the association by using
"Open with...", or selecting Python from the list of installed programs,
very likely the command says only "%1" - that is, the script being open,
but without any additional arguments.

Better if you have administrative rights to do this tasks.

--
Gabriel Genellina
I believe I get the correct results as follows:
==============================================
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

J:\Jim Crerar\mypython\misc>assoc .py
..py=Python.File

J:\Jim Crerar\mypython\misc>ftype Python.File
Python.File="E:\Python25\python.exe" "%1" %*

J:\Jim Crerar\mypython\misc>
===============================================
What else could be wrong?
Thanks,
Jim

Sep 30 '07 #7
Jim
On Sep 30, 6:16 pm, Dennis Lee Bieber <wlfr...@ix.netcom.comwrote:
On Sun, 30 Sep 2007 07:42:56 -0700, Jim <jscre...@compuserve.com>
declaimed the following in comp.lang.python:
What else could be wrong?
Thanks,

Possibly those associations are only defined for your login account,
and not active for the "account" that the task scheduler is running
under?
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfr...@ix.netcom.com wulfr...@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-a...@bestiaria.com)
HTTP://www.bestiaria.com/
As far as know, since I'm the major user of my PC it runs under my
account (computer administrator). It even asked for the password for
my account when I added this scheduled task.
Any further ideas?
Thanks,
Jim

Oct 1 '07 #8
En Sun, 30 Sep 2007 11:42:56 -0300, Jim <js******@compuserve.comescribi�:
On Sep 29, 8:45 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
>The %* at the end is important: if you created the association by using
"Open with...", or selecting Python from the list of installed programs,
very likely the command says only "%1" - that is, the script being open,
but without any additional arguments.
I believe I get the correct results as follows:
==============================================
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

J:\Jim Crerar\mypython\misc>assoc .py
.py=Python.File

J:\Jim Crerar\mypython\misc>ftype Python.File
Python.File="E:\Python25\python.exe" "%1" %*

J:\Jim Crerar\mypython\misc>
===============================================
What else could be wrong?
No more ideas... I think the scheduler just executes the command line, and
if it works in a console, should work in the scheduler too... Unless you
execute the job under another user, who has a different association for
..py files, that's the only reason I can think of.

--
Gabriel Genellina

Oct 1 '07 #9
Jim
On Sep 30, 6:37 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Sun, 30 Sep 2007 11:42:56 -0300, Jim <jscre...@compuserve.comescribi?:


On Sep 29, 8:45 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
The %* at the end is important: if you created the association by using
"Open with...", or selecting Python from the list of installed programs,
very likely the command says only "%1" - that is, the script being open,
but without any additional arguments.
I believe I get the correct results as follows:
==============================================
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
J:\Jim Crerar\mypython\misc>assoc .py
.py=Python.File
J:\Jim Crerar\mypython\misc>ftype Python.File
Python.File="E:\Python25\python.exe" "%1" %*
J:\Jim Crerar\mypython\misc>
===============================================
What else could be wrong?

No more ideas... I think the scheduler just executes the command line, and
if it works in a console, should work in the scheduler too... Unless you
execute the job under another user, who has a different association for
.py files, that's the only reason I can think of.

--
Gabriel Genellina- Hide quoted text -

- Show quoted text -
Just logged into the only other account (my Wife's -- uses only for
hotmail access) and it will not run this scheduled Python program.
Thank you for your help.
Jim

Oct 1 '07 #10
I sometimes see issues like this at work because certain processes, including scheduled tasks if I remember right, can run as Local System user instead of as your user account. That tends to be a real pain for Python or Perl scripts because that means that they don't have the associations configured properly. You can play around a bit as Local System to find out, using an old trick:

open a command prompt and type the following:

at nn:nn /interactive cmd

where nn:nn is one minute from the current time (24 hour clock, so 11:30 pm would be 24:30). This will launch a cmd prompt on your desktop, but running as Local System instead of as yourself. From there you can see what your script does when you run it as the System user, and see what assoc .py says etc.

If you still can't figure it out, the only other things I can think of would be to wrap it in a .bat file and try using that for your scheduled task, or using py2exe to compile your script to an exe which should eliminate the whole file association/PATH issue altogether ;)

Hope that helps,

-Jay

Gabriel Genellina wrote:
No more ideas... I think the scheduler just executes the command line, and
if it works in a console, should work in the scheduler too... Unless you
execute the job under another user, who has a different association for
.py files, that's the only reason I can think of.
Oct 1 '07 #11
Jim wrote:
On Sep 30, 6:16 pm, Dennis Lee Bieber <wlfr...@ix.netcom.comwrote:
>On Sun, 30 Sep 2007 07:42:56 -0700, Jim <jscre...@compuserve.com>
declaimed the following in comp.lang.python:
>>What else could be wrong?
Thanks,
Possibly those associations are only defined for your login account,
and not active for the "account" that the task scheduler is running
under?
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfr...@ix.netcom.com wulfr...@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-a...@bestiaria.com)
HTTP://www.bestiaria.com/

As far as know, since I'm the major user of my PC it runs under my
account (computer administrator). It even asked for the password for
my account when I added this scheduled task.
Any further ideas?
Thanks,
Jim
It could be the scheduler might execute the job as the local system
account (which isn't that by default and I doubt that this is the
problem). If your configuration are not globally they won't be picked up
by that account. Meaning you should set the environment variables not on
user level but system level.

However I have observed some weird issues with scheduler too in the
past, especially when the job is executed while the job owner is not
logged on, apparently the full users profile is not available then.
But that behavior seems to differ on the various windows incarnations
and the color of the moon.

I solved my problem by running the scheduling program not in scheduler
but in cron, but I doubt that is applicable for you :-)

This post doesn't really help much but perhaps it gives some insights on
the problem.

--
mph
Oct 5 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sveta | last post by:
Hi, all! I am new with J2ME. I have application that has form with 2 commands (exit and select). All UI uses are high level API, and it is very important to leave it high-level. This...
2
by: Paul A. Wilson | last post by:
I'm new to Tkinter programming and am having trouble creating a reusable button bar... I want to be able to feed my class a dictionary of button names and function names, which the class will make....
8
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland...
8
by: dakman | last post by:
Recently, I have been needing to do this alot and I can never find a way around it, the main reason I want to do this is because for example in the application I am making right now, it creates a...
1
by: Mike | last post by:
Hello, How do I pass variables to a command text.(C#)Because of the quotes,it seems that the values are not passed. Thanks, Mike
4
by: FluffyCat | last post by:
New on November 29, 2005 for www.FluffyCat.com PHP 5 Design Pattern Examples - the Command Pattern. Since you all enjoyed the Visitor Pattern so much yesterday, today I have the Command Pattern...
2
by: =?Utf-8?B?SmltSGVhdmV5?= | last post by:
Typically, I create a command object and execute it and then if I want to execute additional SQL I create another command object to do this. Is this correct or can/should I re-use the existing...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
0
by: czerwww | last post by:
Can someone please help me? I have class for database connection and I need set command.commandTimeout. How can I do that? Code: Imports System.Data.SqlClient Imports System.Data Public Class...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.