<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Error not returned to command prompt when running sas program via vbscript in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Error-not-returned-to-command-prompt-when-running-sas-program/m-p/416106#M26763</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm trying to run a sas program using vbscript. I'm running vbscript on command prompt using cscript.exe&lt;/P&gt;&lt;P&gt;Below is my vbscript code, where I'm just having "abcdefg" in sas program (to test). Currently I'm testing this to get error message on command prompt, but instead there is no error displayed on command prompt. I can see error message in the log though.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Option Explicit&lt;BR /&gt;Dim app&lt;BR /&gt;Dim str&lt;BR /&gt;Dim prjObject1&lt;BR /&gt;Dim fso&lt;/P&gt;&lt;P&gt;str = "abcdefg"&lt;/P&gt;&lt;P&gt;Call dowork(str)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'shut down the app&lt;BR /&gt;If not (app Is Nothing) Then&lt;BR /&gt;app.Quit&lt;BR /&gt;Set app = Nothing&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sub dowork(codestr)&lt;BR /&gt;On Error Resume Next&lt;BR /&gt;'----&lt;BR /&gt;' Start up Enterprise Guide using the project name&lt;BR /&gt;'----&lt;BR /&gt;Dim prjName&lt;BR /&gt;Dim prjObject&lt;BR /&gt;&lt;BR /&gt;Set app = CreateObject("SASEGObjectModel.Application.7.1")&lt;BR /&gt;If Checkerror("CreateObject") = True Then&lt;BR /&gt;Exit Sub&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;Set prjObject = app.New&lt;/P&gt;&lt;P&gt;Set fso = CreateObject("Scripting.FileSystemObject")&lt;BR /&gt;Set prjObject1 = prjObject.CodeCollection.Add&lt;/P&gt;&lt;P&gt;prjObject1.GenListing = True&lt;BR /&gt;prjObject1.GenSasReport = True&lt;/P&gt;&lt;P&gt;prjObject1.Text = codestr&lt;/P&gt;&lt;P&gt;'-----&lt;BR /&gt;' run the project&lt;BR /&gt;'-----&lt;BR /&gt;prjObject1.run&lt;BR /&gt;If Checkerror("Code.run") = True Then&lt;BR /&gt;Exit Sub&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;' Save the log file to LOCAL disk&lt;BR /&gt;prjObject1.Log.SaveAs(Wscript.ScriptName &amp;amp; ".log")&lt;BR /&gt;&lt;BR /&gt;End Sub&lt;/P&gt;&lt;P&gt;Function Checkerror(fnName)&lt;BR /&gt;Checkerror = False&lt;BR /&gt;&lt;BR /&gt;Dim strmsg&lt;BR /&gt;Dim errNum&lt;BR /&gt;&lt;BR /&gt;If Err.Number &amp;lt;&amp;gt; 0 Then&lt;BR /&gt;strmsg = "Error #" &amp;amp; Hex(Err.Number) &amp;amp; vbCrLf &amp;amp; "In Function " &amp;amp; fnName &amp;amp; vbCrLf &amp;amp; Err.Description&lt;BR /&gt;MsgBox strmsg 'Uncomment this line if you want to be notified via MessageBox of Errors in the script.&lt;BR /&gt;wscript.echo(strmsg)&lt;BR /&gt;wscript.quit(4)&lt;BR /&gt;Checkerror = True&lt;BR /&gt;End If&lt;BR /&gt;&lt;BR /&gt;End Function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ERROR MESSAGE IN LOG:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;abcdefg &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Is there any way to have this error returned in command prompt ? Any help is really appreciated.&lt;/P&gt;&lt;P&gt;Thank You.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 25 Nov 2017 00:41:29 GMT</pubDate>
    <dc:creator>diwakar_atwal</dc:creator>
    <dc:date>2017-11-25T00:41:29Z</dc:date>
    <item>
      <title>Error not returned to command prompt when running sas program via vbscript</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Error-not-returned-to-command-prompt-when-running-sas-program/m-p/416106#M26763</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm trying to run a sas program using vbscript. I'm running vbscript on command prompt using cscript.exe&lt;/P&gt;&lt;P&gt;Below is my vbscript code, where I'm just having "abcdefg" in sas program (to test). Currently I'm testing this to get error message on command prompt, but instead there is no error displayed on command prompt. I can see error message in the log though.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Option Explicit&lt;BR /&gt;Dim app&lt;BR /&gt;Dim str&lt;BR /&gt;Dim prjObject1&lt;BR /&gt;Dim fso&lt;/P&gt;&lt;P&gt;str = "abcdefg"&lt;/P&gt;&lt;P&gt;Call dowork(str)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'shut down the app&lt;BR /&gt;If not (app Is Nothing) Then&lt;BR /&gt;app.Quit&lt;BR /&gt;Set app = Nothing&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sub dowork(codestr)&lt;BR /&gt;On Error Resume Next&lt;BR /&gt;'----&lt;BR /&gt;' Start up Enterprise Guide using the project name&lt;BR /&gt;'----&lt;BR /&gt;Dim prjName&lt;BR /&gt;Dim prjObject&lt;BR /&gt;&lt;BR /&gt;Set app = CreateObject("SASEGObjectModel.Application.7.1")&lt;BR /&gt;If Checkerror("CreateObject") = True Then&lt;BR /&gt;Exit Sub&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;Set prjObject = app.New&lt;/P&gt;&lt;P&gt;Set fso = CreateObject("Scripting.FileSystemObject")&lt;BR /&gt;Set prjObject1 = prjObject.CodeCollection.Add&lt;/P&gt;&lt;P&gt;prjObject1.GenListing = True&lt;BR /&gt;prjObject1.GenSasReport = True&lt;/P&gt;&lt;P&gt;prjObject1.Text = codestr&lt;/P&gt;&lt;P&gt;'-----&lt;BR /&gt;' run the project&lt;BR /&gt;'-----&lt;BR /&gt;prjObject1.run&lt;BR /&gt;If Checkerror("Code.run") = True Then&lt;BR /&gt;Exit Sub&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;' Save the log file to LOCAL disk&lt;BR /&gt;prjObject1.Log.SaveAs(Wscript.ScriptName &amp;amp; ".log")&lt;BR /&gt;&lt;BR /&gt;End Sub&lt;/P&gt;&lt;P&gt;Function Checkerror(fnName)&lt;BR /&gt;Checkerror = False&lt;BR /&gt;&lt;BR /&gt;Dim strmsg&lt;BR /&gt;Dim errNum&lt;BR /&gt;&lt;BR /&gt;If Err.Number &amp;lt;&amp;gt; 0 Then&lt;BR /&gt;strmsg = "Error #" &amp;amp; Hex(Err.Number) &amp;amp; vbCrLf &amp;amp; "In Function " &amp;amp; fnName &amp;amp; vbCrLf &amp;amp; Err.Description&lt;BR /&gt;MsgBox strmsg 'Uncomment this line if you want to be notified via MessageBox of Errors in the script.&lt;BR /&gt;wscript.echo(strmsg)&lt;BR /&gt;wscript.quit(4)&lt;BR /&gt;Checkerror = True&lt;BR /&gt;End If&lt;BR /&gt;&lt;BR /&gt;End Function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ERROR MESSAGE IN LOG:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;abcdefg &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Is there any way to have this error returned in command prompt ? Any help is really appreciated.&lt;/P&gt;&lt;P&gt;Thank You.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2017 00:41:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Error-not-returned-to-command-prompt-when-running-sas-program/m-p/416106#M26763</guid>
      <dc:creator>diwakar_atwal</dc:creator>
      <dc:date>2017-11-25T00:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Error not returned to command prompt when running sas program via vbscript</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Error-not-returned-to-command-prompt-when-running-sas-program/m-p/416119#M26764</link>
      <description>&lt;P&gt;SAS only delivers return codes when run in batch. You can add a check to your vbscript that scans for log lines with WARNING when rc = 1, and WARNING and ERROR when rc = 2.&lt;/P&gt;
&lt;P&gt;IMO catching a non-zero return code and alerting the person responsible should be sufficient; consulting the log is still the domain of human programmers.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2017 06:40:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Error-not-returned-to-command-prompt-when-running-sas-program/m-p/416119#M26764</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-25T06:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: Error not returned to command prompt when running sas program via vbscript</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Error-not-returned-to-command-prompt-when-running-sas-program/m-p/416173#M26765</link>
      <description>&lt;P&gt;Thank you Kurt for your reply. I followed your suggestion and found a solution to my issue. I've added following lines of code into my vbscript.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Dim logfileobj&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Dim logfile&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Set logfileobj = fso.OpenTextFile(Wscript.ScriptName &amp;amp; ".log", 1)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;logfile = logfileobj.ReadAll&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;If InStr(1,logfile, "ERROR", 1) &amp;lt;&amp;gt; 0 then&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; wscript.quit(2)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;end if&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will read the log file and search for the word ERROR (added a parameter '1' for case insensitive search). If found, then it will return the execution to command prompt with ERRORLEVEL = 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Nov 2017 00:00:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Error-not-returned-to-command-prompt-when-running-sas-program/m-p/416173#M26765</guid>
      <dc:creator>diwakar_atwal</dc:creator>
      <dc:date>2017-11-26T00:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: Error not returned to command prompt when running sas program via vbscript</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Error-not-returned-to-command-prompt-when-running-sas-program/m-p/416182#M26766</link>
      <description>&lt;P&gt;Since SAS itself returns with rc = 2 in case of an error, it might be sufficient to retrieve the SAS rc and use it in the exit of the script.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Nov 2017 07:22:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Error-not-returned-to-command-prompt-when-running-sas-program/m-p/416182#M26766</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-26T07:22:19Z</dc:date>
    </item>
  </channel>
</rss>

