bat文件执行过程的控制!!?

yosoft 2003-09-25 09:17:45
现一个问题,我一个过程中要执行两个批处理文件(a.bat,b.bat)!!
必须是a执行完后,才能执行b。
现在情况,程序把a,b提交给windows,b可能比a还提早执行结束。。
有什么好的办法来控制呢?、、、、、??????。。大家提提建议。。
...全文
100 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yosoft 2003-09-28
  • 打赏
  • 举报
回复
好,应该可以了。。。
year2000bug 2003-09-25
  • 打赏
  • 举报
回复
// ronaldli(木的)的方法是最好的,也是最简单的。
//要复杂也有,look。。。。
//WinExecAndWait32是关键。。。
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
function WinExecAndWait32(FileName:String; Visibility : integer): DWORD;stdcall;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

function TForm1.WinExecAndWait32(FileName: String;
Visibility: integer): DWORD;
var
zAppName:array[0..512] of char;
zCurDir:array[0..255] of char;
WorkDir:String;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
begin
StrPCopy(zAppName,FileName);
GetDir(0,WorkDir);
StrPCopy(zCurDir,WorkDir);
FillChar(StartupInfo,Sizeof(StartupInfo),#0);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := Visibility;
if not CreateProcess(
nil,
zAppName, { pointer to command line string }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
false, { handle inheritance flag }
CREATE_NEW_CONSOLE or { creation flags }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name }
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo { pointer to PROCESS_INF }
)
then Result := $FFFFFFFF else begin
WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess,Result);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
//运行批处理文件1.bat
WinExecAndWait32('f:\1.bat',1);
//处理完1.bat后,运行2.bat
WinExecAndWait32('f:\2.bat',1)
end;

end.
ronaldli 2003-09-25
  • 打赏
  • 举报
回复
很简单,在执行前,把a.bat打开,在最后一行加上call b.bat,然后再运行a.bat
最后在适当时候(a.bat肯定运行完的时候,再把a.bat改回来)
yosoft 2003-09-25
  • 打赏
  • 举报
回复
没人理我。。自己up!!!

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧