I'm facing a random problem. When executing SAS programs with VBScript and the SASEGObjectModel.Application.7.1, looping through CodeCollection get stuck sometimes, even if the program execution was succeeded (the final data bases are correctly created in our server). The script simple doesn't go to the next program of CodeCollection (the prompt executing the script still open... ad infinitum). The SAS program It happens is random, also the frequency. I'm going with something like this:
Dim oSasApp
Set oSasApp = CreateObject("SASEGObjectModel.Application.7.1")
oSasApp.SetActiveProfile("some-profile")
Dim oSasProj
Set oSasProj = oSasApp.Open("some-project.egp", "")
Dim oProgramList
Set oProgramList = oSasProj.CodeCollection
Dim programOrder
Set programOrder = ...here I assign the SAS programs order array reading from a .txt...
For Each program in programOrder
For Each sasProgram in oProgramList
If sasProgram.Name = program Then
sasProgram.Run
sasProgram.Log.SaveAs "some-folder/" & sasProgram.Name & ".txt"
End If
Next
Next
oSasProj.Close
oSasApp.Quit
The problem is not the Log saving, as the log txt file of the stucked program is also correctly created.
Any idea? Maybe problems in our SAS server? Should I declare some kind of options?
SAS Guide version: 7.15
Windows: 10
Tks
So... for people facing the same problem. As I commented above, if I press enter on prompt the script flows again. So it is waiting for my input, for reasons I can't tell. I did 2 things to get around it. Not sure if all of them are necessary or if only one solves it, but here it goes:
First, by VBScript I turned off a list of generations and I applied a delay after the SAS program runs:
For Each program in programOrder
For Each sasProgram i oProgramList
If sasProgram.Name = program Then
sasProgram.GenSasReport = False
sasProgram.GenHTML = False
sasProgram.GenListing = False
sasProgram.GenPDF = False
sasProgram.GenRTF = False
sasProgram.Run
WScript.Sleep(2000)
sasProgram.Log.SaveAs "some-folder/" & sasProgram.Name & ".txt"
End If
Next
Next
Them, in my batch file, wich I use to call the VBScript with the "cscript" command, I set it to apply "y" to every single message the VBScript could ask:
cd ./script-folder
echo y | cscript script-file-name.vbs
And that is it.
Related
I'm using a VBScript to write into a configuration file config.txt, then run an executable SomeName.exe with the configuration I set.
The excecutable is not mine, I cannot interact with it.
The result is written in another text file Result.txt.
In the end, it looks like this
Set objShell = CreateObject("WScript.Shell")
For MyParameter = mystart to myend
'here I overwrite conf.txt with MyParameter value
Rt = objShell.run(SomeName.exe, 1, True) '--> True means "wait until the end before processing"
Next
What I'd like to do is to check the result.txt file and, if it's ok, stop the .exe and resume the loop with next value of MyParameter.
I already know how to read the file and decide whether the result is good enough or not (basically I read the last line and compare it with something else, very easy stuff) with a second script.
What I don't know is how to make this two scripts work together.
For now the only way I have is to run manually my second script and make it check from time to time (with Sleep function) if the result is good. In that case, I use taskill /im "SomeName.exe". But it's quite ugly and I have to run it with an infinite loop since I don't know how long it will take to SomeName.exe to reach the result (it's a simulation, it can be very very long !).
Have you got any idea on how to do that ?
Thanks a lot in advance for any help you can give me,
Why use WaitOnReturn=True?
Change that to False and then add your script code loop that checks for final line right after it.
So I've recorded a script using the SAP GUI recorder. I'm basically just running 7 reports and saving the contents to an excel file. The code is uninspiring, just some variation of.
session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "SAP_ALL.TXT"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 11
But sometimes there are no records in the report.
I suspect there is something I can check to either save the report or move on using if/then/else but cannot find a good example. How do I catch and recover from this or other errors?
Is there a way to to sapshcut�or structure the script to avoid this problem?
Also, is there a way to execute the script from the command line, passing in the userid and password as parameters?
Relevant examples welcome. I'd RTFM but I don't have one.
If the report is a grid, then you could try the following.
for example:
...
session.findById("wnd[0]/tbar[1]/btn[8]").press
on error resume next
'This command must be recorded once in your environment. It's a mouseclick in the first line.
session.findById("wnd[0]/usr /subSUB_AREA_ROOT:SAPLREIS_GUI_CONTROLLER:0200/subSUB_AREA:SAPLREIS_GUI_CONTROLLER:1000/cntlCC_LIST/shellcont/shell").currentCellRow = 1
if err.number = 0 then
on error goto 0
...
session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "SAP_ALL.TXT"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 11
...
else
on error goto 0
...
end if
...
Please take a look at the following link:
VBA 2010 - Hide all SAP windows using .iconify
Regards,
ScriptMan
We have many UFT test scripts with many datasets.
In order to perform a quick check of the scripts, we want to run every script using only, for each script, the first dataset of the data table.
We know how to do it unitary (with the "Test settings" window) but not globally.
We don't even know if it's possible, if you have some info please tell me!
Thank you
Use the below VBscript and change the path C:\QTP\Scripts\MyScript with your script path. This scripts will open and run the UFT test and set the data table iteration to 1st row only. You can also loop this script to execute all UFT Tests with one iteration only.
Dim App 'As Application
Set App = CreateObject("QuickTest.Application")
Set qtResultOpt=CreateObject("QuickTest.RunResultsOptions")
qtResult.ResultsLocation="C:\Temp\"
App.Launch
App.Visible = True
App.Test.Settings.Run.IterationMode = "rngIterations"
App.Test.Settings.Run.StartIteration = 1
App.Test.Settings.Run.EndIteration = 1
App.Open "C:\QTP\Scripts\MyScript", True
Set objTest=qtApp.Test
objTest.Run qtResultOpt
I have a problem: I want to run a file from lotusscript code:
Dim result As Integer
result = Shell("D:\testF.dsx", 1)
And I get the following error: Illegal function call.
If I want to execute it from formula it works:
#Command([Execute]; "D:\\testF.dsx")
Thanks a lot!
I had the same problem with the shell function in lotus script with PDF files. And my workaround is to use the windows scripting host to launch the file. I am pretty sure this will solve your problem too.
Set objShell = CreateObject("WScript.Shell")
returnValue = objShell.Run("d:\testF.dsx", 3, false)enter code here
It is not possible to "Execute" a Textfile. usually there is no "run" function defined for dsx- files.
You could do it like:
Dim result as Integer
result = Shell("notepad.exe D:\testF.dsx", 1)
Or find out, which program is linked to dsx (via registry) and execute the corresponding exe with filename as Parameter. If the filename contains spaces, then it has to be enclosed:
Dim result as Integer
result = Shell({notepad.exe "D:\testF.dsx"}, 1)
And reading your last question this approach for sure is NOT the right for your request. You have to use "open" in order to process files... Like Per Hendrik told you in his response.
I had similar problems passing parameters to Outlook.
On some windows machines, this #Formula worked perfectly:
#Command([Execute]; "Outlook.exe"; "/recycle")
On Windows Terminal Servers, it caused Outlook to be unable to parse the "/recycle"
The Shell-command from LotusScript wasn't even able to locate the Outlook.exe, as it was not in the PATH.
Ralf's code helped me in this respect. The "WScript.Shell" seems able to interact with Windows registry settings. Anyway, here is the code that works for activating an open Outlook window.
Dim objShell, returnValue
Set objShell = CreateObject("WScript.Shell")
returnValue = objShell.Run("outlook.exe /recycle", 3, False)
firts excuse me for my English it`s super Freak. Sorry
I have a big problem , i need finish my applicatión in VB6.0 for a test in my High Schooll and i can`t find the solution, My app open a FFmpeg.EXE file which open a cmd window Prompt and start a trascoding process, i need link the last line generated into the Prompt of the CMD window (Or top Bottom) , in this line exists Values what change , in this trascoding process the result are bit Rates , which fluctuates acording to others var.
The idea it´s what into the form of my app i can read this line in real time to bulid a progress bar (File Size/Bitrate average)=time to process.
Can you help me. Thanks for the answer....
Put a reference to Windows Scripting Host Object Model and try this snippet
Option Explicit
Private Sub Command1_Click()
Dim oExec As WshExec
Dim sRow As String
With New WshShell
Set oExec = .Exec("tasklist.exe")
End With
Do While oExec.Status = WshRunning
sRow = oExec.StdOut.ReadLine
If InStr(1, sRow, "vb6.exe", vbTextCompare) > 0 Then
MsgBox sRow, vbExclamation
End If
Loop
End Sub
Basicly try executing FFmpeg.EXE and ReadLine until you find some key text.
Send the output to a textfile then read this textfile.
Should look something like this:
ping >e:\test.txt
Where ping is the FFmpge.EXE and e:\test.txt the output textfile
rdkleine
I read your answer and this is great work very good , only that it shows in the log a death value "text", and i need the value of fluctuates bitrates of conversion , which changes in real time in the prompt of the cmd window. i'm trying now with the source code of wqw , i'm working in there.
Thak's for your answer..