Kinook Software Forum

Go Back   Kinook Software Forum > Visual Build Professional > [VBP] General Discussion
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-18-2004, 07:46 PM
jmm jmm is online now
Registered User
 
Join Date: 07-29-2004
Posts: 10
How to run DOS commands in Run Script

I have written a Run Script step (in VBScript) to emulate our existing DOS batch file based build system. I assumed that since the DOSCMD macro shows up via the "Insert Macro" button, that I could use it to execute DOS commands within my VBScript code. But when I try this:

%DOSCMD% "echo hello"

I get:

Error at Line 327, Column 4 (Expected statement)
Code: C:\WINDOWS\system32\cmd.exe /C "echo hello"

Do I have to use a "Run Program" step to execute DOS commands? If so, how do I do that programatically within my VBScript?
Reply With Quote
  #2  
Old 08-19-2004, 04:01 PM
kevina kevina is online now
Registered User
 
Join Date: 03-27-2003
Posts: 825
The recommended way would be to use the Builder.RunProgramEx method.

Example: Builder.RunProgramEx "calc.exe"

See the help file for details (also available online at: http://www.kinook.com/VisBuildPro/Ma...amexmethod.htm)
Reply With Quote
  #3  
Old 09-02-2004, 07:47 PM
jmm jmm is online now
Registered User
 
Join Date: 07-29-2004
Posts: 10
How to run DOS commands in Run Script

Thanks for the reply!

First, when I search the VBP Forum for the keyword "RunProgramEx", why do I get no results?

Second, while I can run calc.exe in your example without problem, I can't use Builder.RunProgramEx the way I need to. I get what I believe to be file-exclusively-opened access problems with the bat-file I wish to run via Builder.RunProgramEx. In the following sub I create a bat-file to execute using Builder.RunProgramEx:

sub RunCmds(cmds, ProjectDir)

Dim MyFso, tf, BatFile, DosCmd

BatFile = "c:\build\RunBuild2.bat"
Set MyFso = vbld_FSO()
Set tf = MyFso.CreateTextFile(BatFile, true)
tf.Write("cd " & ProjectDir & vbCrLf & cmds)
tf.Close

DosCmd = BatFile
Builder.RunProgramEx DosCmd

end sub

The first time I run the job, I get this rather quiet error:
...
1 of 1 project(s) updated
9/2/2004 5:25:18 PM: Build successfully completed.
Error at Line 318, Column 2
Step 'Parse top-level build.bat' failed
Build ended.

Note: Line 318 is "Builder.RunProgramEx DosCmd".

Now when I run it again I get this error:
...
1 of 1 project(s) updated
9/2/2004 5:35:55 PM: Build successfully completed.
Error at Line 312, Column 2 (Permission denied)
Step 'Parse top-level build.bat' failed
Build ended.

Note: Line 312 is "Set tf = MyFso ...".

If I try to delete or change the bat-file outside of VBP, I get access denied errors until I exit VBP.
Reply With Quote
  #4  
Old 09-02-2004, 10:35 PM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
When I search the forums for RunProgramEx, I get one result: this thread.

Batch files must be executed under the command shell (see 'Run Program Action' in the help index for details). Try

DosCmd = "%DOSCMD% call """ & BatFile & """"
Reply With Quote
  #5  
Old 09-03-2004, 12:52 PM
jmm jmm is online now
Registered User
 
Join Date: 07-29-2004
Posts: 10
I am confused by this post. As the thread title implies, I am trying to run a DOS command from within VBScript. How would I use 'Run Program Action' from within VBScript?

Your previous reply was to use the Builder.RunProgramEx method. That solution seems to work at a basic level. I was seeking help re file-exclusively-opened access problems in creating and using the bat-file in the Builder.RunProgramEx method. See my posting from 9/2/04 for details.
Reply With Quote
  #6  
Old 09-03-2004, 01:35 PM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
The reference to the Run Program Action help topic was only pointing out where to look for a more detailed explanation of how to invoke batch files from a Run Program Action or RunProgramEx.

The permission denied / access error is most likely occurring because you aren't invoking the batch file like you need to, leading to an error which prevents the .Close code from being executed. Again, try:

DosCmd = "%DOSCMD% call """ & BatFile & """"

instead of

DosCmd = BatFile

in your script code.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT -5. The time now is 01:12 PM.


Copyright © 1999-2023 Kinook Software, Inc.