| |
cluster:scripting_in_windows [2018/10/02 13:53] – created support | cluster:scripting_in_windows [2024/11/11 21:01] (current) – removed mcloughlin |
---|
======Scripting in Windows====== | |
This page will introduce some methods for scripting within Windows. It will focus on using the DOS-like ''cmd'' window using the example of converting a bunch of .eps files to .pdf. A good use for this is if you want to reformat Stata graphs. | |
| |
=====Entering Windows Commands===== | |
| |
To enter DOS commands in Windows, go to Start -> Run and type "cmd" and press enter. You get a black box that says something like "C:\ " in the upper left. Here, you can type shell commands for Windows. For a reference on some of the commands, see [[http://commandwindows.com/command1.htm|this]]. | |
| |
I will assume that you already have "Ghostscript" installed. If not, you could get it from [[http://sourceforge.net/projects/ghostscript/|SourceForge]], among other places. | |
| |
First, make sure that you can run ''eps2pdf'' in the command window. Change to a directory where you have an eps file with | |
<code>cd C:\directory\with\eps\</code> | |
| |
Then, type: | |
<code>eps2pdf file.eps</code> | |
| |
This should create a file named "file.pdf" in the directory "C:\directory\with\eps\" | |
| |
If that worked, you have two options to automate your task further. You can try to do a for loop as follows. Type the command: | |
<code>FOR %EPSFILE IN C:\directory\with\eps\*.eps DO eps2pdf %EPSFILE</code> | |
| |
=====Writing a Script or ''Batch File''===== | |
This should create a .pdf version of every eps file in the directory. The other option is that you can create a batch file with line for each command that you want to enter. For example, if you know the 6 file names that you will want to convert to pdf (perhaps because you create them from a Stata .do file), you can write the same commands that you would run every time in a file. To do this, open Notepad or another text editor. Then, enter the following text | |
<code>cd C:\directory\with\eps\ | |
eps2pdf eps1.eps | |
eps2pdf eps2.eps | |
... | |
eps2pdf eps3.eps</code> | |
Save this file as epsbatchfile.bat. Now, you can go back into the shell, navigate to the directory where you saved "epsbatchfile.bat" and enter the command | |
<code>epsbatchfile.bat</code> | |
This will run the commands above! | |
| |
A final thing that might make this even better is to integrate this into your Stata code. By using the command ''winexec "C:\path\to\epsbatchfile.bat"'' within Stata, you can have Stata convert all of your .eps files to PDFs as it is running. | |
| |