GIF89a; %PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY
Server IP : 134.29.175.74 / Your IP : 216.73.216.160 Web Server : nginx/1.10.2 System : Windows NT CST-WEBSERVER 10.0 build 19045 (Windows 10) i586 User : Administrator ( 0) PHP Version : 7.1.0 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /nginx/html/JimMartinson/_Archive/CST1861/dostips.com/ |
Upload File : |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html lang="en-US"><head><link media="all" href="DOS%20Batch%20-%20Interfacing%20non%20DOS%20Software_files/widget64.css" type="text/css" rel="stylesheet"> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> <meta content="TRUE" name="MSSmartTagsPreventParsing"> <meta http-equiv="expires" content="-1"> <meta http-equiv="pragma" content="no-cache"> <meta content="all" name="robots"> <meta name="keywords" content="dos,functions,vista,xp,command line,batch,examples,substring,variables,copies,date"> <link rel="Stylesheet" type="text/css" media="all" href="DOS%20Batch%20-%20Interfacing%20non%20DOS%20Software_files/_style.css"> <link rel="shortcut icon" href="http://www.dostips.com/favicon.ico"> <link rel="icon" href="http://www.dostips.com/animated_favicon1.gif" type="image/gif"> <title>DOS Batch - Interfacing non DOS Software</title> </head> <body><div id="_atssh" style="visibility: hidden; height: 1px; width: 1px; position: absolute; z-index: 100000;"><iframe src="DOS%20Batch%20-%20Interfacing%20non%20DOS%20Software_files/sh49.htm" style="height: 1px; width: 1px; position: absolute; z-index: 100000; border: 0pt none; left: 0pt; top: 0pt;" title="AddThis utility frame" id="_atssh503"></iframe></div> <div class="nav"> <!-- AddThis Button BEGIN --> <div class="addthis_toolbox addthis_default_style"> <a href="#" title="Send to Facebook" class="addthis_button_facebook at300b"><span class="at300bs at15nc at15t_facebook"></span></a> <a href="#" title="Email" class="addthis_button_email at300b"><span class="at300bs at15nc at15t_email"></span></a> <a href="#" title="Save to Favorites" class="addthis_button_favorites at300b"><span class="at300bs at15nc at15t_favorites"></span></a> <a href="#" title="Print" class="addthis_button_print at300b"><span class="at300bs at15nc at15t_print"></span></a> <span class="addthis_separator">|</span> <a title="View more services" href="http://www.addthis.com/bookmark.php?v=250&username=cmdtips" class="addthis_button_expanded at300m"><span class="at300bs at15nc at15t_expanded"></span>More</a> <div class="atclear"></div></div> <script type="text/javascript" src="DOS%20Batch%20-%20Interfacing%20non%20DOS%20Software_files/addthis_widget.js"></script> <!-- AddThis Button END --> <br> <div class="navi"> <a href="http://www.dostips.com/"><img src="DOS%20Batch%20-%20Interfacing%20non%20DOS%20Software_files/TitleDostips.JPG" alt="DosTips.com" height="80"></a> <br><span style="font-size: 9px; font-weight: bold;">for Windows7,VISTA,XP,NT,Server 2000,</span> <br><span style="font-size: 9px; font-weight: bold;">Server 2003,Server 2008</span> <br> <br> <!-- SiteSearch Google --> <form style="margin: 5" method="get" action="http://www.dostips.com/DtGeneSearch.php" target="_top"> <span style="font-size: 11px;">Search:</span> <input name="domains" value="cmdtips.com" type="hidden"> <input name="q" size="12" maxlength="255" value="Google" onclick="this.value=''" type="text"> <input name="sitesearch" value="www.dostips.com" type="hidden"> <input name="sa" src="DOS%20Batch%20-%20Interfacing%20non%20DOS%20Software_files/search.gif" value="Search" alt="Search" style="width: 20px; height: 20px; vertical-align: middle; border: medium none;" type="image"> <input name="client" value="pub-4331089886589220" type="hidden"> <input name="forid" value="1" type="hidden"> <input name="ie" value="ISO-8859-1" type="hidden"> <input name="channel" value="0649133363" type="hidden"> <input name="oe" value="ISO-8859-1" type="hidden"> <input name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:11" type="hidden"> <input name="hl" value="en" type="hidden"> </form> <!-- SiteSearch Google --> <br> <ul> <li class="nsel"><a href="http://www.dostips.com/">Home</a> <ul> <li class="nsel"> </li> </ul> </li> <li class="nsel"><a>Source Script</a> <ul> <li class="nsel"><a href="http://www.dostips.com/DtCodeBatchFiles.php">Batch Files</a> </li> <li class="nsel"><a href="http://www.dostips.com/DtCodeFunctions.php">Functions</a> </li> <li class="nsel"><a href="http://www.dostips.com/DtCodeCmdLib.php">Function Library</a> </li> <li class="nsel"><a href="http://www.dostips.com/DtCodeSnippets.php">Script Snippets</a> </li> <li class="ysel"><a href="http://www.dostips.com/DtCodeInterfacing.php">Interfacing</a> </li> <li class="nsel"> </li> </ul> </li> <li class="nsel"><a>Tips and Tricks</a> <ul> <li class="nsel"><a href="http://www.dostips.com/DtTipsXCopy.php">Copy Tips</a> </li> <li class="nsel"><a href="http://www.dostips.com/DtTipsMenu.php">Menu in Batch</a> </li> <li class="nsel"><a href="http://www.dostips.com/DtTipsStringManipulation.php">String Manipulation</a> </li> <li class="nsel"><a href="http://www.dostips.com/DtTipsStringOperations.php">String Operations</a> </li> <li class="nsel"><a href="http://www.dostips.com/DtTipsDateTime.php">Date and Time</a> </li> <li class="nsel"><a href="http://www.dostips.com/DtTipsArithmetic.php">Arithmetic</a> </li> <li class="nsel"><a href="http://www.dostips.com/DtTipsFtpBatchScript.php">FTP Batch Script</a> </li> <li class="nsel"><a href="http://www.dostips.com/DosCommandIndex.php">Command Index</a> </li> <li class="nsel"> </li> </ul> </li> <li class="nsel"><a>Tutorials</a> <ul> <li class="nsel"><a href="http://www.dostips.com/DtTutoFirstBatch.php">My First Batch</a> </li> <li class="nsel"><a href="http://www.dostips.com/DtTutoFramework.php">Solid Framwork</a> </li> <li class="nsel"><a href="http://www.dostips.com/DtTutoFunctions.php">Functions</a> </li> <li class="nsel"><a href="http://www.dostips.com/DtTutoPersistency.php">Persistency</a> </li> <li class="nsel"> </li> </ul> </li> <li class="nsel"><a href="http://www.dostips.com/forum/viewforum.php?f=3">Forum</a> <ul> <li class="nsel"> </li> </ul> </li> <li class="nsel"><a href="http://www.dostips.com/DtGeneGeneral.php">General</a> <ul> <li class="nsel"><a href="http://www.dostips.com/DtGeneTermsOfUse.php">Terms of Use</a> </li> <li class="nsel"><a href="http://www.dostips.com/DtGeneEnabler.php">Enablers</a> </li> <li class="nsel"><a href="http://www.dostips.com/DtGeneAboutUs.php">About Us</a> </li> <li class="nsel"><a href="http://www.dostips.com/DtGeneContact.php">Contact Us</a> </li> <li class="nsel"> </li> </ul> </li> <li class="nsel"><a>Other</a> <ul> <li class="nsel"><a href="http://www.dot5hosting.com/join/index.bml?AffID=570595&LinkName=dot5txt">Get Web Hosting</a> </li> <li class="nsel"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9018663"><marquee scrollamount="2" width="120">Want donate a cup of Cafe? . click . </marquee></a> </li> <li class="nsel"> </li> </ul> </li> </ul> </div> </div> <h1>DOS Batch - Interfacing non DOS Software</h1> <span class="shortText">Embed other languages into your batch, like: Perl, SQL, FTP, ...</span><br><br> <table class="posts"> </table> <br><table class="menu" cellpadding="0" cellspacing="0"> <tbody><tr><td colspan="2"> </td></tr> <tr><td class="title"><a href="http://www.dostips.com/DtCodeInterfacing.php">DOS Batch - Interfacing non DOS Software</a></td> <td class="text">Embed other languages into your batch, like: Perl, SQL, FTP, ...</td> </tr> <tr><td class="title"><a href="#Batch.FtpBatchAutoLogin">FTP - Automatic Login</a></td> <td class="text">Automatically login to your FTP session with a single click.</td> </tr> <tr><td class="title"><a href="#Batch.FtpBatchUsingVariables">FTP - Resolving Environment Variables</a></td> <td class="text">Creating FTP script on the fly at runtime and using variables within the FTP script.</td> </tr> <tr><td class="title"><a href="#Batch.FtpBatch">FTP - Simple Single Batch</a></td> <td class="text">FTP script and batch in a single file.</td> </tr> <tr><td class="title"><a href="#Batch.FtpBatchLoginSharing">FTP Scripts Sharing Login Info</a></td> <td class="text">Manage the FTP login separately from your FTP scripts.</td> </tr> <tr><td class="title"><a href="#Interfacing.Sql">OSQL.EXE - Run SQL script from DOS Batch</a></td> <td class="text">SQL script and dos batch script in one file, the One-File Solution</td> </tr> <tr><td class="title"><a href="#Interfacing.Sql2">OSQL.EXE - Run SQL script from DOS Batch, passing parameters</a></td> <td class="text">Run SQL scripts with parameters passed in from the batch script.</td> </tr> <tr><td class="title"><a href="#Interfacing.Perl">Perl - Perl Script within a DOS Batch</a></td> <td class="text">Perl script and batch in a single file.</td> </tr> <tr><td class="title"><a href="#Interfacing.Perl2">Perl Script within a DOS Batch with delayed exit</a></td> <td class="text">Perl script and batch in a single file.</td> </tr> </tbody></table> <hr> <a name=""></a> <a name="Batch.FtpBatchAutoLogin"></a> <div style="float: right;"><font color="darkblue"><a href="#">TOP</a><br><font size="1">2009-12-06</font></font></div> <h2>FTP - Automatic Login - Automatically login to your FTP session with a single click</h2> <table class="posts"> <tbody><tr> <td class="title" valign="top">Description:</td> <td class="text" valign="top"><p>If you frequently find yourself calling <a href="http://www.dostips.com/DosCommandIndex.htm#FTP">FTP</a> from the command line, each time having to login and change directory and change FTP modes, until you finally get where you want be in order to do some real work then you may wish to get there with a singe click. </p><p>This little batch can connect to your FTP server and logs you in before it gives you the prompt. You can easily add more FTP commands to it, like changing directories or switching to binary mode or whatever you like to be done before taking over control on the FTP prompt. </p><p>The FTP connection information is embedded within the batch itself. The batch connects to an FTP server by executing itself in FTP context using the <a href="http://www.dostips.com/DosCommandIndex.htm#FTP">FTP</a> -s option. Once executing in FTP context it executes all FTP commands listed in the file. By omitting the final <a href="http://www.dostips.com/DosCommandIndex.htm#FTP">FTP</a> "bye" command it will stop at the FTP prompt and wait for user input. </p><p>Optionally a FTP script can be provided as input stream, that way multiple FTP scripts can share the same login information. Example: </p><p>FtpLogin.bat <script1.ftp</p></td> </tr> <tr> <td class="title" valign="top">Script:</td> <td class="text" valign="top"><span style="float:right;">Download: <a href="http://www.dostips.com/FtpLogin.bat">FtpLogin.bat</a> </span> <table class="btchscr"><tbody><tr> <td class="numbrs" align="right" nowrap="nowrap"><code><a name="1">1.</a><br><a name="2">2.</a><br><a name="3">3.</a><br><a name="4">4.</a><br><a name="5">5.</a><br></code></td> <td class="code" nowrap="nowrap"><code><span style="color=#000000">@ftp -i -s:"<span class="c_pvar">%~f0</span>"&GOTO:EOF</span><br> <span style="color=#000000">open example.com</span><br> <span style="color=#000000">username</span><br> <span style="color=#000000">password</span><br> <span style="color=#000000">pwd</span><br> </code></td> </tr></tbody></table> </td> </tr> <tr> <td class="title" valign="top">Script Output:</td> <td class="text" valign="top"><table class="dosw" border="0" cellpadding="3" cellspacing="2"> <tbody><tr><td class="title"> <img src="DOS%20Batch%20-%20Interfacing%20non%20DOS%20Software_files/SysIcon.JPG" alt="DOS"> Script Ouput </td></tr> <tr><td class="text"><pre>ftp> @ftp -i -s:"%~f0"&GOTO:EOF Invalid command. ftp> open example.com Connected to example.com. 220- 220 FTP Server ready User (example.com:(none)): 331 Password required 230 User logged in ftp> pwd 257 "/" is the current directory ftp> </pre></td></tr></tbody></table></td> </tr> </tbody></table> <hr> <a name=""></a> <a name="Batch.FtpBatchUsingVariables"></a> <div style="float: right;"><font color="darkblue"><a href="#">TOP</a><br><font size="1">2008-10-17</font></font></div> <h2>FTP - Resolving Environment Variables - Creating FTP script on the fly at runtime and using variables within the FTP script</h2> <table class="posts"> <tbody><tr> <td class="title" valign="top">Description:</td> <td class="text" valign="top"><p>This batch executed the FTP script embedded within the batch. All variables in the FTP script will be resolved. </p><p>The <a href="http://www.dostips.com/DosCommandIndex.htm#FOR">FOR</a> loop extracts the FTP script into a temporary file. It the <a href="http://www.dostips.com/DosCommandIndex.htm#ECHO">ECHO</a> command is being <a href="http://www.dostips.com/DosCommandIndex.htm#CALL">CALL</a>ed for each line in order to resolve the variables. </p><p>Variables can be used within the FTP script the same way as in a batch script, including any <a href="http://www.dostips.com/DtTipsStringManipulation.php">string manipulation</a> and command line arguments like %1 %2 %~n0 %* and so on. </p><p>All batch lines start with semicolon so that they will be ignored by the <a href="http://www.dostips.com/DosCommandIndex.htm#FOR">FOR</a> loop. Semicolon is the default end-of-line (EOL) character used by the <a href="http://www.dostips.com/DosCommandIndex.htm#FOR">FOR</a> command.</p></td> </tr> <tr> <td class="title" valign="top">Script:</td> <td class="text" valign="top"> <table class="btchscr"><tbody><tr> <td class="numbrs" align="right" nowrap="nowrap"><code><a name="1">1.</a><br><a name="2">2.</a><br><a name="3">3.</a><br><a name="4">4.</a><br><a name="5">5.</a><br><a name="6">6.</a><br><a name="7">7.</a><br><a name="8">8.</a><br><a name="9">9.</a><br><a name="10">10.</a><br><a name="11">11.</a><br><a name="12">12.</a><br><a name="13">13.</a><br><a name="14">14.</a><br><a name="15">15.</a><br></code></td> <td class="code" nowrap="nowrap"><code><span style="color=#000000">;@echo off</span><br> <span style="color=#000000">;(for /f "usebackq delims=" <span class="c_pvar">%%A</span> in ("<span class="c_pvar">%~f0</span>") do call echo.<span class="c_pvar">%%A</span>)>"%temp%\<span class="c_pvar">%~n0</span>.ftp"</span><br> <span style="color=#000000">;ftp -i -s:"%temp%\<span class="c_pvar">%~n0</span>.ftp"</span><br> <span style="color=#000000">;GOTO:EOF</span><br> <span style="color=#000000"></span><br> <span style="color=#000000">open example.com</span><br> <span style="color=#000000">username</span><br> <span style="color=#000000">password</span><br> <span style="color=#000000">!:--- FTP commands below here ---</span><br> <span style="color=#000000">cd public_html/%COMPUTERNAME%</span><br> <span style="color=#000000">binary</span><br> <span style="color=#000000">hash on</span><br> <span style="color=#000000">%*</span><br> <span style="color=#000000">disconnect</span><br> <span style="color=#000000">bye</span><br> </code></td> </tr></tbody></table> </td> </tr> </tbody></table> <hr> <a name=""></a> <a name="Batch.FtpBatch"></a> <div style="float: right;"><font color="darkblue"><a href="#">TOP</a><br><font size="1">2008-01-01</font></font></div> <h2>FTP - Simple Single Batch - FTP script and batch in a single file</h2> <table class="posts"> <tbody><tr> <td class="title" valign="top">Description:</td> <td class="text" valign="top"><p>Embed FTP script into a batch script. Add this line at the beginning of the FTP script:</p> <b>@ftp -i -s:"%~f0"&GOTO:EOF</b> <p>The "FTP -s:ftpscript.txt" option executes a FTP script wheres "%~f0" resolved to the name of the running batch file. "GOTO:EOF" ends the batch script and makes sure the FTP script doesn`t run as part of the batch. <br>Good: You end up with only one file that contains the batch script and the FTP script combined. <br>Minor flaw: The batch command in the first line causes an "Invalid command." error when executed in FTP context, however the FTP execution will continue.</p> Features: <ul> <li>Single file to distribute combining batch and FTP script</li> </ul></td> </tr> <tr> <td class="title" valign="top">Script:</td> <td class="text" valign="top"> <table class="btchscr"><tbody><tr> <td class="numbrs" align="right" nowrap="nowrap"><code><a name="1">1.</a><br><a name="2">2.</a><br><a name="3">3.</a><br><a name="4">4.</a><br><a name="5">5.</a><br><a name="6">6.</a><br><a name="7">7.</a><br><a name="8">8.</a><br><a name="9">9.</a><br><a name="10">10.</a><br><a name="11">11.</a><br></code></td> <td class="code" nowrap="nowrap"><code><span style="color=#000000">@ftp -i -s:"<span class="c_pvar">%~f0</span>"&GOTO:EOF</span><br> <span style="color=#000000">open example.com</span><br> <span style="color=#000000">username</span><br> <span style="color=#000000">password</span><br> <span style="color=#000000">!:--- FTP commands below here ---</span><br> <span style="color=#000000">lcd c:\MyLocalDirectory</span><br> <span style="color=#000000">cd public_html/MyRemoteDirectory</span><br> <span style="color=#000000">binary</span><br> <span style="color=#000000">mput "*.*"</span><br> <span style="color=#000000">disconnect</span><br> <span style="color=#000000">bye</span><br> </code></td> </tr></tbody></table> </td> </tr> <tr> <td class="title" valign="top">Script Output:</td> <td class="text" valign="top"><table class="dosw" border="0" cellpadding="3" cellspacing="2"> <tbody><tr><td class="title"> <img src="DOS%20Batch%20-%20Interfacing%20non%20DOS%20Software_files/SysIcon.JPG" alt="DOS"> Script Ouput </td></tr> <tr><td class="text"><pre>ftp> @ftp -i -s:"%~f0"&GOTO:EOF Invalid command. ftp> open example.com User (Username:(none)): ftp> !:--- FTP commands below here --- ftp> lcd c:\MyLocalDirectory Local directory now c:\MyLocalDirectory. ftp> cd public_html/MyRemoteDirectory ftp> binary ftp> !: mput "*.*" ftp> disconnect ftp> bye </pre></td></tr></tbody></table></td> </tr> </tbody></table> <hr> <a name=""></a> <a name="Batch.FtpBatchLoginSharing"></a> <div style="float: right;"><font color="darkblue"><a href="#">TOP</a><br><font size="1">2009-12-06</font></font></div> <h2>FTP Scripts Sharing Login Info - Manage the FTP login separately from your FTP scripts</h2> <table class="posts"> <tbody><tr> <td class="title" valign="top">Description:</td> <td class="text" valign="top"><p>If you have multiple FTP scripts that all use the same login information to your FTP site then you may wish to manage the login information separately from your FTP scripts in a single place. That way if the username, password or hostname for the FTP connection changes you only need to edit a single place instead of having to edit all FTP scripts one by one. </p><p>This automatic login script (also described in detail earlier) can be used to execute different FTP scripts that share the same login information stored within the batch file. </p><p>Example: <b>FtpLogin.bat script1.ftp</b> </p><p><b>Note:</b> The FTP scripts passed into the batch must have the login sequence removed. </p><p><b>Note:</b> The FTP script executes even if the connection sequence fails potentially causing `Not connected` and other errors. This is no different from regularly executing <a href="http://www.dostips.com/DosCommandIndex.htm#FTP">FTP</a> with -s option. </p></td> </tr> <tr> <td class="title" valign="top">Script:</td> <td class="text" valign="top"><span style="float:right;">Download: <a href="http://www.dostips.com/FtpLoginSharing.bat">FtpLoginSharing.bat</a> </span> <table class="btchscr"><tbody><tr> <td class="numbrs" align="right" nowrap="nowrap"><code><a name="1">1.</a><br><a name="2">2.</a><br><a name="3">3.</a><br><a name="4">4.</a><br></code></td> <td class="code" nowrap="nowrap"><code><span style="color=#000000">@type %1|ftp -i -s:"<span class="c_pvar">%~f0</span>"&GOTO:EOF</span><br> <span style="color=#000000">open example.com</span><br> <span style="color=#000000">username</span><br> <span style="color=#000000">password</span><br> </code></td> </tr></tbody></table> </td> </tr> </tbody></table> <hr> <a name="_Toc134470226"></a> <a name="Interfacing.Sql"></a> <div style="float: right;"><font color="darkblue"><a href="#">TOP</a><br><font size="1">2008-01-01</font></font></div> <h2>OSQL.EXE - Run SQL script from DOS Batch - SQL script and dos batch script in one file, the One-File Solution</h2> <table class="posts"> <tbody><tr> <td class="title" valign="top">Description:</td> <td class="text" valign="top"><p>Embedding SQL script within a batch script is just as easy. The following batch script executes itself in SQL context. The trick is the GOTO command in the first line of the script. When executing GOTO START in batch context than the command processor will jump to the label ":START" and execute the batch script. The batch script will then run the OSQL.EXE using the batch file itself as SQL file argument to be executed. When subsequently executing the GOTO START line in SQL context, the query language processor will jump to the label "START:" and execute the SQL queries. In fact the file can be opened and executed in Query Analyzer as is, since the batch script in the file looks like a comment to the query language processor.</p></td> </tr> <tr> <td class="title" valign="top">Script:</td> <td class="text" valign="top"><span style="float:right;">Download: <a href="http://www.dostips.com/Batch4SQL.bat">Batch4SQL.bat</a> </span> <table class="btchscr"><tbody><tr> <td class="numbrs" align="right" nowrap="nowrap"><code><a name="1">1.</a><br><a name="2">2.</a><br><a name="3">3.</a><br><a name="4">4.</a><br><a name="5">5.</a><br><a name="6">6.</a><br><a name="7">7.</a><br><a name="8">8.</a><br><a name="9">9.</a><br><a name="10">10.</a><br><a name="11">11.</a><br><a name="12">12.</a><br><a name="13">13.</a><br><a name="14">14.</a><br><a name="15">15.</a><br><a name="16">16.</a><br><a name="17">17.</a><br><a name="18">18.</a><br><a name="19">19.</a><br><a name="20">20.</a><br><a name="21">21.</a><br></code></td> <td class="code" nowrap="nowrap"><code><span style="color=#000000">GOTO START</span><br> <span style="color=#000000">-- DOS jumps to the ':START' label</span><br> <span style="color=#000000">-- SQL jumps to the 'START:' label</span><br> <span style="color=#000000">-- Source http://www.dostips.com</span><br> <span style="color=#000000"></span><br> <span style="color=#000000">/* Begin of SQL comment, this makes the BATCH script invisible for SQL</span><br> <span style="color=#000000"><span class="c_cmmt">:: BATCH starts below here</span></span><br> <span style="color=#000000"><span class="c_labl"><a name="START">:START</a></span><span class="c_cmmt"></span></span><br> <span style="color=#000000">@echo off</span><br> <span style="color=#000000">CLS</span><br> <span style="color=#000000"></span><br> <span style="color=#000000">OSQL.EXE -n -E -w 65536 -d NORTHWIND -i "<span class="c_pvar">%~f0</span>"</span><br> <span style="color=#000000"></span><br> <span style="color=#000000">PAUSE&GOTO:EOF</span><br> <span style="color=#000000">*/</span><br> <span style="color=#000000"></span><br> <span style="color=#000000">-- SQL starts below here</span><br> <span style="color=#000000">START:</span><br> <span style="color=#000000">GO</span><br> <span style="color=#000000">SELECT * FROM AUTHOR</span><br> <span style="color=#000000">GO</span><br> </code></td> </tr></tbody></table> </td> </tr> </tbody></table> <hr> <a name="_Toc134470227"></a> <a name="Interfacing.Sql2"></a> <div style="float: right;"><font color="darkblue"><a href="#">TOP</a><br><font size="1">2008-01-01</font></font></div> <h2>OSQL.EXE - Run SQL script from DOS Batch, passing parameters - Run SQL scripts with parameters passed in from the batch script</h2> <table class="posts"> <tbody><tr> <td class="title" valign="top">Description:</td> <td class="text" valign="top"><p>Now we can embed SQL queries into a batch file. But how can we pass arguments from the batch script into SQL? This can be done using a temporary table. Temporary tables live as long as the connection to the SQL Server. But how can we fill a temporary table with runtime data and execute the embedded SQL script without creating two separate SQL Server connections by calling OSQL.EXE twice? The trick is that OSQL allows to use the -i and -q option at the same time whereas: </p><ul> <li>-q specifies a query string to be executed</li> <li>-i specifies a filename with SQL syntax to be executed</li> </ul> Both the query string and the SQL file will be executed using the same Server connection. Some testing shows that the query string -q will always be executed before the -I SQL file, which allows us to use a query string to set up a temporary table. <p></p></td> </tr> <tr> <td class="title" valign="top">Script:</td> <td class="text" valign="top"><span style="float:right;">Download: <a href="http://www.dostips.com/Batch4SQL2.bat">Batch4SQL2.bat</a> </span> <table class="btchscr"><tbody><tr> <td class="numbrs" align="right" nowrap="nowrap"><code><a name="1">1.</a><br><a name="2">2.</a><br><a name="3">3.</a><br><a name="4">4.</a><br><a name="5">5.</a><br><a name="6">6.</a><br><a name="7">7.</a><br><a name="8">8.</a><br><a name="9">9.</a><br><a name="10">10.</a><br><a name="11">11.</a><br><a name="12">12.</a><br><a name="13">13.</a><br><a name="14">14.</a><br><a name="15">15.</a><br><a name="16">16.</a><br><a name="17">17.</a><br><a name="18">18.</a><br><a name="19">19.</a><br><a name="20">20.</a><br><a name="21">21.</a><br><a name="22">22.</a><br><a name="23">23.</a><br><a name="24">24.</a><br><a name="25">25.</a><br><a name="26">26.</a><br><a name="27">27.</a><br><a name="28">28.</a><br><a name="29">29.</a><br><a name="30">30.</a><br><a name="31">31.</a><br><a name="32">32.</a><br><a name="33">33.</a><br><a name="34">34.</a><br><a name="35">35.</a><br><a name="36">36.</a><br><a name="37">37.</a><br><a name="38">38.</a><br><a name="39">39.</a><br><a name="40">40.</a><br><a name="41">41.</a><br><a name="42">42.</a><br><a name="43">43.</a><br><a name="44">44.</a><br><a name="45">45.</a><br><a name="46">46.</a><br><a name="47">47.</a><br><a name="48">48.</a><br><a name="49">49.</a><br><a name="50">50.</a><br><a name="51">51.</a><br><a name="52">52.</a><br></code></td> <td class="code" nowrap="nowrap"><code><span style="color=#000000">GOTO START</span><br> <span style="color=#000000">-- DOS jumps to the ':START' label</span><br> <span style="color=#000000">-- SQL jumps to the 'START:' label</span><br> <span style="color=#000000">-- Source http://www.dostips.com</span><br> <span style="color=#000000"></span><br> <span style="color=#000000">/* Begin of SQL comment, this makes the BATCH script invisible for SQL</span><br> <span style="color=#000000"><span class="c_cmmt">:: BATCH starts below here</span></span><br> <span style="color=#000000"><span class="c_labl"><a name="START">:START</a></span><span class="c_cmmt"></span></span><br> <span style="color=#000000">@echo off</span><br> <span style="color=#000000">CLS</span><br> <span style="color=#000000"></span><br> <span style="color=#000000">set /p AuthorName=Author Name:</span><br> <span style="color=#000000">set /p AuthorCity=Author City:</span><br> <span style="color=#000000"></span><br> <span style="color=#000000"><span class="c_cmmt">rem.-------------------------------------------------------------------------</span></span><br> <span style="color=#000000"><span class="c_cmmt">rem.Execute THIS file in SQL context transmitting arguments per temp table</span></span><br> <span style="color=#000000">set Args=</span><br> <span style="color=#000000"></span><br> <span style="color=#000000"><span class="c_cmmt">rem.--BEGIN ARGS SECTION ------------------</span></span><br> <span style="color=#000000">set Args=%Args% INSERT #ArgsTable VALUES ('AuthorName','%AuthorName%')</span><br> <span style="color=#000000">set Args=%Args% INSERT #ArgsTable VALUES ('AuthorCity','%AuthorCity%')</span><br> <span style="color=#000000"><span class="c_cmmt">rem.--END ARGS SECTION ------------------</span></span><br> <span style="color=#000000"></span><br> <span style="color=#000000">set Args= -q "SET NOCOUNT ON CREATE TABLE #ArgsTable(Arg char(16) PRIMARY KEY, Val char(32)) %Args%"</span><br> <span style="color=#000000"></span><br> <span style="color=#000000">OSQL.EXE -n -E -w 65536 -d NORTHWIND %Args% -i "<span class="c_pvar">%~f0</span>"</span><br> <span style="color=#000000"></span><br> <span style="color=#000000">PAUSE&GOTO:EOF</span><br> <span style="color=#000000">*/</span><br> <span style="color=#000000"></span><br> <span style="color=#000000">-- SQL starts below here</span><br> <span style="color=#000000">START:</span><br> <span style="color=#000000">GO</span><br> <span style="color=#000000"></span><br> <span style="color=#000000">DECLARE @AuthorName varchar(128)</span><br> <span style="color=#000000">DECLARE @AuthorCity varchar(128)</span><br> <span style="color=#000000"></span><br> <span style="color=#000000">--Set defaults for values as needed</span><br> <span style="color=#000000">SET @AuthorName = ''</span><br> <span style="color=#000000">SET @AuthorCity = ''</span><br> <span style="color=#000000"></span><br> <span style="color=#000000">--Copy data from temporary table into variables</span><br> <span style="color=#000000">IF EXISTS (SELECT name, type FROM tempdb..sysobjects WHERE name like '#ArgsTable_%' AND type = 'U')</span><br> <span style="color=#000000">BEGIN</span><br> <span style="color=#000000"> SELECT @AuthorName=Val FROM #ArgsTable WHERE Arg='AuthorName'</span><br> <span style="color=#000000"> SELECT @AuthorCity=Val FROM #ArgsTable WHERE Arg='AuthorCity'</span><br> <span style="color=#000000">END</span><br> <span style="color=#000000"></span><br> <span style="color=#000000">print @AuthorName</span><br> <span style="color=#000000">print @AuthorCity</span><br> <span style="color=#000000"></span><br> <span style="color=#000000">GO</span><br> </code></td> </tr></tbody></table> </td> </tr> </tbody></table> <hr> <a name="_Toc134470224"></a> <a name="Interfacing.Perl"></a> <div style="float: right;"><font color="darkblue"><a href="#">TOP</a><br><font size="1">2008-01-01</font></font></div> <h2>Perl - Perl Script within a DOS Batch - Perl script and batch in a single file</h2> <table class="posts"> <tbody><tr> <td class="title" valign="top">Description:</td> <td class="text" valign="top"><p>It`s nice not to have to type <b>"perl -s Batch4Parl.pl"</b> into the command line and rather being able to just double click a Perl script in Explorer. The trick of renaming the Perl .pl to a batch .bat file and wrapping a batch script around the Perl script is well known under Perl monks. However the solution I have seen so far needed batch code before and after the Perl script where as the solution presented below only needs some lines of DOS at the top. The added DOS script is generic and works independent from the name of the file.</p> <p>When running the batch the DOS command interpreter will read the first lines and execute the file itself in Perl context.</p></td> </tr> <tr> <td class="title" valign="top">Script:</td> <td class="text" valign="top"><span style="float:right;">Download: <a href="http://www.dostips.com/Batch4Perl.bat">Batch4Perl.bat</a> </span> <table class="btchscr"><tbody><tr> <td class="numbrs" align="right" nowrap="nowrap"><code><a name="1">1.</a><br><a name="2">2.</a><br><a name="3">3.</a><br><a name="4">4.</a><br><a name="5">5.</a><br></code></td> <td class="code" nowrap="nowrap"><code><span style="color=#000000">@<span class="c_cmmt">rem = 'source http://www.dostips.com</span></span><br> <span style="color=#000000">@CD/d"<span class="c_pvar">%~dp0</span>"&perl -s "<span class="c_pvar">%~nx0</span>" %*&Exit/b&:';</span><br> <span style="color=#000000"></span><br> <span style="color=#000000">#perl script starts below here</span><br> <span style="color=#000000">print 'Hi there! DOS rocks!\n'</span><br> </code></td> </tr></tbody></table> </td> </tr> </tbody></table> <hr> <a name="_Toc134470225"></a> <a name="Interfacing.Perl2"></a> <div style="float: right;"><font color="darkblue"><a href="#">TOP</a><br><font size="1">2008-01-01</font></font></div> <h2>Perl Script within a DOS Batch with delayed exit - Perl script and batch in a single file</h2> <table class="posts"> <tbody><tr> <td class="title" valign="top">Description:</td> <td class="text" valign="top"><p>This example works just as the previews one but will wait 4 seconds before the application finally closes. This is just enough time to inspect the screen output before the window vanishes. The delay can probably be done much easier in Perl, but somebody just starting on Perl might find this still useful.</p></td> </tr> <tr> <td class="title" valign="top">Script:</td> <td class="text" valign="top"><span style="float:right;">Download: <a href="http://www.dostips.com/Batch4Perl2.bat">Batch4Perl2.bat</a> </span> <table class="btchscr"><tbody><tr> <td class="numbrs" align="right" nowrap="nowrap"><code><a name="1">1.</a><br><a name="2">2.</a><br><a name="3">3.</a><br><a name="4">4.</a><br><a name="5">5.</a><br><a name="6">6.</a><br><a name="7">7.</a><br><a name="8">8.</a><br><a name="9">9.</a><br></code></td> <td class="code" nowrap="nowrap"><code><span style="color=#000000">@<span class="c_cmmt">rem = 'Perl, ccperl will read this as an array of assignment & skip this block</span></span><br> <span style="color=#000000">@CD /d "<span class="c_pvar">%~dp0</span>"</span><br> <span style="color=#000000">@perl -s "<span class="c_pvar">%~nx0</span>" %*</span><br> <span style="color=#000000">@FOR /L <span class="c_pvar">%%c</span> in (4,-1,1) do @(TITLE <span class="c_pvar">%~nx0</span> - <span class="c_pvar">%%c</span>s to close & ping -n 2 -w 1000 127.0.0.1 >NUL)</span><br> <span style="color=#000000">@TITLE Press any key to close the window&ECHO.&GOTO:EOF</span><br> <span style="color=#000000">@<span class="c_cmmt">rem ';</span></span><br> <span style="color=#000000"></span><br> <span style="color=#000000">#perl script starts below here</span><br> <span style="color=#000000">print 'Hi there! DOS rocks!\n'</span><br> </code></td> </tr></tbody></table> </td> </tr> </tbody></table> <br><br> <a href="http://www.amazon.com/gp/product/0735622620?ie=UTF8&tag=dos01-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0735622620"><img src="DOS%20Batch%20-%20Interfacing%20non%20DOS%20Software_files/51JXrVTAGnL.jpg" border="0"></a><img src="DOS%20Batch%20-%20Interfacing%20non%20DOS%20Software_files/ir_002.gif" alt="" style="border: medium none ! important; margin: 0px ! important;" height="1" border="0" width="1"> <a href="http://www.amazon.com/gp/product/0735625956/ref=as_li_tf_il?ie=UTF8&tag=dos01-20&linkCode=as2&camp=217145&creative=399353&creativeASIN=0735625956"><img src="DOS%20Batch%20-%20Interfacing%20non%20DOS%20Software_files/q.jpg" border="0"></a><img src="DOS%20Batch%20-%20Interfacing%20non%20DOS%20Software_files/ir.gif" alt="" style="border: medium none ! important; margin: 0px ! important;" height="1" border="0" width="1"> <script type="text/javascript"><!-- google_ad_client = "pub-4331089886589220"; /* 468x60, created 12/30/07 */ google_ad_slot = "8403807900"; google_ad_width = 468; google_ad_height = 60; //--> </script> <script type="text/javascript" src="DOS%20Batch%20-%20Interfacing%20non%20DOS%20Software_files/show_ads.js"> </script><ins style="display:inline-table;border:none;height:60px;margin:0;padding:0;position:relative;visibility:visible;width:468px"><ins id="aswift_0_anchor" style="display:block;border:none;height:60px;margin:0;padding:0;position:relative;visibility:visible;width:468px"><iframe allowtransparency="true" hspace="0" marginwidth="0" marginheight="0" onload="var i=this.id,s=window.google_iframe_oncopy,H=s&&s.handlers,h=H&&H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&&d&&(!d.body||!d.body.firstChild)){if(h.call){i+='.call';setTimeout(h,0)}else if(h.match){i+='.nav';w.location.replace(h)}s.log&&s.log.push(i)}" vspace="0" id="aswift_0" name="aswift_0" style="left: 0pt; position: absolute; top: 0pt;" frameborder="0" height="60" scrolling="no" width="468"></iframe></ins></ins> <div class="bot"> <script type="text/javascript"> /*********************************************** * IFrame SSI script II- Copyright Dynamic Drive DHTML code library (http://www.dynamicdrive.com) * Visit DynamicDrive.com for hundreds of original DHTML scripts * This notice must stay intact for legal use ***********************************************/ //Input the IDs of the IFRAMES you wish to dynamically resize to match its content height: //Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none: var iframeids=["myframe"] //Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended): var iframehide="yes" var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1] var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers function resizeCaller() { var dyniframe=new Array() for (i=0; i<iframeids.length; i++){ if (document.getElementById) resizeIframe(iframeids[i]) //reveal iframe for lower end browsers? (see var above): if ((document.all || document.getElementById) && iframehide=="no"){ var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i]) tempobj.style.display="block" } } } function resizeIframe(frameid){ var currentfr=document.getElementById(frameid) if (currentfr && !window.opera){ currentfr.style.display="block" if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax currentfr.height = currentfr.Document.body.scrollHeight; if (currentfr.addEventListener) currentfr.addEventListener("load", readjustIframe, false) else if (currentfr.attachEvent){ currentfr.detachEvent("onload", readjustIframe) // Bug fix line currentfr.attachEvent("onload", readjustIframe) } } } function readjustIframe(loadevt) { var crossevt=(window.event)? event : loadevt var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement if (iframeroot) resizeIframe(iframeroot.id); } function loadintoIframe(iframeid, url){ if (document.getElementById) document.getElementById(iframeid).src=url } if (window.addEventListener) window.addEventListener("load", resizeCaller, false) else if (window.attachEvent) window.attachEvent("onload", resizeCaller) else window.onload=resizeCaller </script> <center> <br> <br> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script><script src="DOS%20Batch%20-%20Interfacing%20non%20DOS%20Software_files/ga.js" type="text/javascript"></script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-280191-1"); pageTracker._initData(); pageTracker._trackPageview(); </script> <br> </center> <iframe id="myframe" src="DOS%20Batch%20-%20Interfacing%20non%20DOS%20Software_files/viewforum.htm" marginwidth="0" marginheight="0" style="overflow: visible; display: block;" frameborder="0" height="2824" width="100%"></iframe></div> </body></html>