Solved

VFP9 wscript.shell .run won't work with task scheduler

Posted on 2014-10-10
9
591 Views
Last Modified: 2014-10-16
I have written the following code in vfp9.  The code is supposed to run the Google Account Manager (gam) to create a file of current gmail accounts.  This works fine when run from the desktop but, It won't work when using the task scheduler.  It never executes the .run instruction (according to the task manager).  Any help would be appreciated.
loShell=Createobject('Wscript.shell')
lcCmd = Getenv("ComSpec") + [ /C ] && There is a space before and after the ‘/C’
lcCmd=lcCmd+[c:\gam\gam.exe print users allfields > C:\gam\GamData\allusers.csv] 
loShell.Run(lcCmd,IwindowStyle,bWaitOnReturn)

Open in new window

0
Comment
Question by:zanthras
  • 3
  • 3
  • 2
9 Comments
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 40374704
%Comspec% is the environment variable specifying what is executed, if you use the VFP RUN or ! command.
You're overcomplicating things.

If you want to call c:\gam\gam.exe why don't you do so?

RUN c:\gam\gam.exe print users allfields > C:\gam\GamData\allusers.csv

Open in new window


As far as I read documentation about the gam.exe it requires an initialisation where you have to log in to an administrative google apps account and grant access to give the EXE authentication for any further functionality, that may be your problem.

Bye, Olaf.
0
 

Author Comment

by:zanthras
ID: 40374709
As I said in my question, This code runs just fine, including GAM when run from the desktop.  Gam functions flawlessly.  I am trying to suppress any output to the screen.  The IWindowstyle  (loShell.Run(lcCmd,IwindowStyle,bWaitOnReturn) variable is set to zero.  That hides any window that  the shell.run might open.  That can't be done using the 'RUN' command.
0
 
LVL 41

Expert Comment

by:pcelba
ID: 40374732
Processes in the Task Scheduler are different from ones executed in interactive Desktop session and some commands do not work as expected.

OK, why do you need FoxPro to run the batch? You may simply execute some .BAT file in the Task Scheduler:
rem ... List all Gmail accounts
c:\gam\gam.exe print users allfields > C:\gam\GamData\allusers.csv
rem ... and now execute VFP to do the rest of work (if necessary):
VFP9.EXE <YourVFPCodeFileName> 

Open in new window

You may also use PowerShell.

If your code "never executes the .run instruction " what it does? Does it hang? Does it exit? Does it even start? Did you ensure the CREATEOBJECT() was successful?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 40374745
You have scheduled what? This code compiled as EXE? or this code in a PRG? Pavel suggests running a bat file with your command and I would second that, you don't need VFP at all, only if you do further things in VFP with the CSV output.

Also: If task scheduler is involved, how much does it matter if a window displays. You typically do such things at a server not being used by a user at the same time anyway.

Bye, Olaf.
0
 
LVL 41

Expert Comment

by:pcelba
ID: 40374759
Also the VFP RUN command supports parameter /N2 or /N7 which allows to run the application minimized which is acceptable even when the user is logged in the interactive session.
0
 

Accepted Solution

by:
zanthras earned 0 total points
ID: 40375157
There are problems using the 'RUN'.  For one thing, VFP runs the batch and keeps on proccessing.  I need the output of the first GAM command to do what I need to do in the rest of the program.

Anyway, it turns out thatthe windows task scheduler just can't do what i want so, I bought a third party scheduler (system scheduler from Splinterware http://www.splinterware.com).  It works just fine now.

Thanks for your help
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 40375535
No objection, but the MS task scheduler is ok, you may have needed to configure some options correctly, eg running with a certain windows account.

Just your sentiment about the scheduler is wrong. I do run several tasks running VFP EXEs. Also waiting for external processes in VFP is possible. In case you RUN /N you don't wait, in case of RUN you do wait, also you may wait for the CSV file and in a loop try to get exclusive access, so you see gam.exe is finished with it. You can also use CreateProcess instead and WaitForSingleObject.

Anyway, it's fine you can solve your problem with a third party scheduler. You could respect the time we invested, but again I won't object.

Bye, Olaf.
0
 

Author Closing Comment

by:zanthras
ID: 40383876
My solution didn't require a VFP 'work-a-round' .  The program itself is okay but Microsofts' scheduler was lacking.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
either24  challenge 19 97
groupNoAdj 7 97
delphi parse string to params 3 123
Problem to Alipay 10 24
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to implement Singleton Design Pattern in Java.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question