Solved

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

Posted on 2014-10-10
9
627 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 42

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
Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

 
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 42

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
scoresSpecial  challenge 13 68
WPF issue with Trigger 2 146
Python 3.5.2 32 virtualenv problems 3 100
Adjust the codes 3 63
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

732 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