Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to call a .bat file from a script?

Status
Not open for further replies.

pwjgirl

Programmer
Dec 27, 2000
4
0
0
US
I have never used ASPECT before and now I am faced with an entire application development project using it! Has anyone called a .bat file from a script before? If so, how did you do it? Thank-you so much for any help you might offer.
 
Executes a DOS command or another program within a separate DOS window.

string Any executable command as it would appear on the DOS command line.
MINIMIZED Forces Procomm Plus to execute the command or program as a minimized icon.
MAXIMIZED Executes the command or program in a full-screen DOS window.
HIDDEN Forces Procomm Plus to execute the command or program with no visible DOS window.
intvar An optional integer variable assigned the task id number of the DOS window. This task id can be used in the taskactivate, taskexit, ddeinit and other commands.

Example

proc main
string Cmd ; DOS command to execute.

Cmd = "dir *.* > temp.fil" ; Set DOS command to execute.
DOS Cmd HIDDEN ; Run DOS command hidden.
; This is an easy way to get a list of files from a
; directory into a file. If you're using DOS 5.0
; or greater, you can specify the /B option to get
; a cleaner listing.
endproc

Comments

If one of the optional parameters MINIMIZED, MAXIMIZED or HIDDEN is not used, the application runs using a default window size and position.
The dos command is equivalent to using the Run command in the Windows File Manager with the string "COMMAND /C cmndname" as an argument. The DOS session uses the settings in _default.pif, unless a .pif file already exists for command.com.
If the path to the executable command is not specified, the program or external DOS command must be either in the current directory or in the directory specified in your DOS path. ASPECT will, however, change to the directory specified in $USERPATH before attempting to execute the dos command. Also, command.com must be in the directory from which you started your computer, typically the root directory of drive C or in the location specified by the COMSPEC environment variable.

dos can be tested with the if SUCCESS statement, returning false if command.com is not found or true if it is found, even if the command to be executed is invalid or fails to execute. The run command provides a similar function and provides better testing for DOS external commands and other programs.
If you use the dos command to execute a program or command that requires user input, be sure that the user is aware of this, since processing will halt until the required input is provided. The dos command will execute both standard DOS batch files and internal DOS commands. The run command only accepts .com and .exe programs. Under Windows Standard mode, a DOS session will run full screen.

See also

run, shell and taskexists; DOS- or Disk-Related Commands.
 
Thanks so much for this info, I am still working on the application so this will be more than helpful! I truly appreciate you taking the time to provide such detail info. Hopefully now...I can get this thing up and running once and for all! Thanks Again!!
 
I am also trying to call a DOS .bat file from a procomm script and it is not working, I see a DOS window flash up for a second but cannot get a log or anything to tell what is happening. Below is the aspect code I am using.

Proc MAIN
String cmd
cmd = "c:\hp_9b047\hpb047UP > LOG.log"
DOS cmd MAXIMIZED
;
ENDPROC

 
You can use that (100% will work):

=======================================================
proc main
string CmdLine
integer x
strfmt CmdLine "C:\Mapi\sendmail.bat"
run CmdLine x
endproc
=======================================================

For CmdLine you can write any path you need.
x is a variable (you can use for other aplication but it must be here)
It should be work.
Use exactly in this form (included x variable)

Good luck,
Geo
 
I am having no luck with running a batch file from Aspect.
The batch file runs fine from the Run command window of the PC. I have tried executing this batch command two different ways in my script and neither one works. The dos windows flashes briefly and closes before I can see what it says and the command is not executed. Here are the two ways I have tried.

proc main
string cmd
integer x
strfmt cmd "sipreg.bat"
run cmd x
endproc

and -

proc main
string cmd
strfmt cmd "sipreg.bat"
dos cmd
endproc
 
Hemi,

Looks like you are opening a DOS shell, but DOS doesn't see the file you are trying to open. Try using the RUN command, and placing the full path in the statement like this:

proc main
RUN "C:\ThisOrThatFolder\sipreg.bat"
endproc


See if that works. If not, post a response and let me know.
Eddie
 

Thanks for the attempt Eddie but using run also did not work. I see the same thing, the dos window flashes momentarily on the screen. The help file for the RUN command says it can't be used for batch files. It says to use the DOS command for that but that didn't work either. I have verified that I can manually run my batch file from any directory. This makes me believe that it is not a path issue. I just have doubts that the DOS command can be used to run batch files.
The help says it can but I have only seen the DOS command work for running dos commands like dir, cls, and cd.
 
I've been playing with the DOS command, but no matter how I word it - it does the same thing you are experiencing - command line window pops up for about a millisecond, and closes. Batch file won’t trigger.

I know the RUN command works with batch files. I've used it with success in the past. The one below is straight from a script I just tested, so if the path and filename are correct, it should work fine.

proc main
run "c:\Temp Script Test\Test Open.bat"
endproc

That command emulates the same RUN you say is working off of windows, so if you've verified the path and filename are the same, I'm at a loss. Maybe you could post the actual script and batch file contents if it still doesn't work.
 
Eddie, I think you are correct. I tried to use the run command with a simple batch file that just opens notepad and it all worked fine. So the issue is with my batch file.
Like I said, the batch file works fine by itself, but not when called by Aspect.

This is not the correct forum for batch file issues but I will present it here anyway.

The batch file runs a utility called SIPp (used for testing VoIP calls).

Batch File -

Echo Off
Echo Start SIPP
sipp 192.168.200.80:5060 -i 192.168.200.56 -p 5060 -m 1 -sf \scenarios\phoneregister_uac.xml

Aspect Script -

proc main

run "c:\Batch\sipreg.bat"

endproc
 
Well, I'm afraid that's one I can't help you with. The last ditch idea I'd have would be to throw a pause statement after the run command to give the bat file time to execute, but truth be told - I doubt that will help. We know the batch file is triggering, but it's just not successful. That's a whole 'nother can o' worms my friend.... Sorry I couldn't be more of a help.
 
What if you cut down the batch file so it just reads:

sipp 192.168.200.80:5060 -i 192.168.200.56 -p 5060 -m 1 -sf \scenarios\phoneregister_uac.xml

or just use the run command with that command line?

 
Thanks Eddie and Knob for your excellent suggestions. I have tried them with success. Placing the Pauses in the batch file revealed a further clue. The window can now been seen to see what is failing. When I run the script the command window stays open and reveals that the problem is it doesn't recognize sipp to be an external command or operable program. Which it is. -

c:\program files\symantec\procomm plus\aspect>Echo Off
Press any key to continue . . .
'sipp' is not recognized as an internal or external command,
operable program or batch file.
Press any key to continue . . .

This pointed to problems finding sipp in the path so I changed my batch file and added - cd C:\Program Files\SIPp.
This placed me in the SIPp directory and eliminated a search through the path. It now works!!!

Thanks so much!
Mitch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top