Add Stop Start Batch File Script To Model

764
7
Jump to solution
11-21-2012 06:06 AM
MarkYoung
Occasional Contributor
Hi,
I have a batch script on my server which stops and starts web services. Is there any way I can incorporate this into my actual model?
Thanks
Mark
0 Kudos
1 Solution

Accepted Solutions
MathewCoyle
Frequent Contributor
You should just be able to drag and drop the python script directly into your model. You could also make a script tool from it.

View solution in original post

0 Kudos
7 Replies
MathewCoyle
Frequent Contributor
I'm not sure about referencing it directly, but you can create a simple python script that opens a batch file that you can import into your model. Here is a fairly detailed Stack Overflow post explaining it far better than I could.

http://stackoverflow.com/questions/1818774/python-subprocess
0 Kudos
MarkYoung
Occasional Contributor
Thanks for your reply but I am afraid I know absolutely nothing about python. I have read a few posts about incorporating python with model builder - how do you combine the two? Do you have to export the whole model to python then add in the additional python script?
Thanks
Mark
0 Kudos
MarkYoung
Occasional Contributor
Hi,
Solved this in the end. I was stopping services to register a feature class as versioned to then delete features then append features from a new feature class. I removed the register as versioned task and all updates wen through fine:)
Mark
0 Kudos
MathewCoyle
Frequent Contributor
No, you should just be able to add a simple python script to your model and call it the same way you would a tool. Would be slightly different if you need to pass parameters to it. Something like this is a basic example.

from subprocess import Popen
Popen("batchfile.bat", cwd=r"c:\directory\containing\batchfile").wait()
0 Kudos
MarkYoung
Occasional Contributor
Although I have solved this particular issue updating data it would be good to get this sussed though for reference. Don't understand how to add the script which calls the batch file to the model. Do you right click in the model and add script from somewhere or do you copy paste the code to a .txt file, rename to .py then drag drop into the model.. hope that makes sense,
Thanks
Mark
0 Kudos
MathewCoyle
Frequent Contributor
You should just be able to drag and drop the python script directly into your model. You could also make a script tool from it.
0 Kudos
MarkYoung
Occasional Contributor
I was trying to right click in the model, right click within the tool box couldn't find add script option - but eventually got it by right clicking over the actual toolbox and select add - script.
Thanks for your help with this - it's appreciated.
Mark
0 Kudos