瀏覽代碼

Improve ISPP's Exec.

Martijn Laan 1 年之前
父節點
當前提交
400a9adc60
共有 4 個文件被更改,包括 27 次插入6 次删除
  1. 4 4
      Projects/ISPP/Help/ispp.xml
  2. 20 2
      Projects/ISPP/IsppFuncs.pas
  3. 2 0
      Projects/Src/InstFunc.pas
  4. 1 0
      whatsnew.htm

+ 4 - 4
Projects/ISPP/Help/ispp.xml

@@ -812,10 +812,10 @@ The list of options is provided at the end of this topic.</para>
 					<pre><line><b>int</b> Exec(<b>str</b> 1, <b>str</b>? 2, <b>str</b>? 3, <b>int</b>? 4, <b>int</b>? 5, <b>int</b>? 6)</line></pre>
 				</section>
 				<description>
-					<para>Executes specified executable file.</para>
-					<para>First argument specifies the filename of the module to execute.</para>
-					<para>Second argument may be used to specify command line to execute.</para>
-					<para>Third argument may be used to specify the working directory of the process.</para>
+					<para>Executes specified executable or batch file.</para>
+					<para>First argument specifies the filename of the executable or batch file. If this does not includes quotes then the function will add them automatically. If you have a single string containing both a filename and parameters (e.g. a command line obtained from an UninstallString registry value), you need not separate them yourself; just pass '>' in this argument, and the full command line in the second argument. (Note that when this is done, the function's special platform-independent support for .bat and .cmd files is disabled; it simply passes the specified command line to CreateProcess without any processing.)</para>
+					<para>Second argument may be used to specify parameters for the process.</para>
+					<para>Third argument may be used to specify the working directory of the process. If this is omitted or empty it will try to extract a pathname from the first argument and use that as the initial current directory for the process.</para>
 					<para>Fourth argument may be set to zero if you don't wish to wait for the process to finish, and non-zero otherwise. By default, non-zero value is assumed.</para>
 					<para>Fifth argument may be any of the <synel>SW_*</synel> constants defined in &builtins;. For GUI processes, it specifies the default value the first time ShowWindow is called. By default, SW_SHOWNORMAL (i. e. 1) is assumed.</para>
 					<para>Sixth argument may be set to zero if you don't wish to log output, and non-zero otherwise. By default, non-zero value is assumed. Has no effect if the fourth argument is set to zero.</para>

+ 20 - 2
Projects/ISPP/IsppFuncs.pas

@@ -640,8 +640,26 @@ var
   StartupInfo: TStartupInfo;
   ProcessInfo: TProcessInformation;
 begin
-  CmdLine := Filename + ' ' + Params;
-  if WorkingDir = '' then WorkingDir := ExtractFilePath(Filename);
+  {Also see InstFuncs' InstExec which is very similar }
+
+  if Filename = '>' then
+    CmdLine := Params
+  else begin
+    if (Filename <> '') and (Filename[1] <> '"') then
+      CmdLine := '"' + Filename + '"'
+    else
+      CmdLine := Filename;
+    if Params <> '' then
+      CmdLine := CmdLine + ' ' + Params;
+    if SameText(PathExtractExt(Filename), '.bat') or
+       SameText(PathExtractExt(Filename), '.cmd') then begin
+      { See InstExec for explanation }
+      CmdLine := '"' + AddBackslash(GetSystemDir) + 'cmd.exe" /C "' + CmdLine + '"'
+    end;
+    if WorkingDir = '' then
+      WorkingDir := PathExtractDir(Filename);
+  end;
+
   FillChar (StartupInfo, SizeOf(StartupInfo), 0);
   StartupInfo.cb := SizeOf(StartupInfo);
   StartupInfo.dwFlags := STARTF_USESHOWWINDOW;

+ 2 - 0
Projects/Src/InstFunc.pas

@@ -864,6 +864,8 @@ var
   StartupInfo: TStartupInfo;
   ProcessInfo: TProcessInformation;
 begin
+  {Also see IsppFuncs' Exec which is very similar }
+
   if Filename = '>' then
     CmdLine := Params
   else begin

+ 1 - 0
whatsnew.htm

@@ -141,6 +141,7 @@ end;</pre>
   <li>Added new <tt>[Files]</tt> section flag <tt>signcheck</tt>. Instructs the compiler check the original source files for a digital signature before storing them.</li>
   <li>During startup Setup would always ask Windows to create any missing <tt>{usercf}</tt>, <tt>{userpf}</tt>, and <tt>{usersavedgames}</tt> folders. It no longer does until the script asks for the folder. Note that scripts running in administrative install mode should not do this because it violates the <a href="ishelp/index.php?topic=setup_useduserareaswarning">used user areas warning</a>.</li>
   <li>Added support for IIS group users identifiers (<tt>iisiusrs</tt>) for use in <tt>Permissions</tt> parameters.</li> 
+  <li>ISPP change: Support function <tt>Exec</tt> no longer requires the filename parameter to be quoted if it contains spaces. Additionally it now supports &quot;&gt;&quot; as a filename and now includes special platform-independent support for .bat and .cmd files, both just like for example the <tt>[Run]</tt> section.</li>
   <li>Pascal Scripting change: Type <tt>TShellFolderID</tt> was removed because it wasn't used by any support function.</li>
   <li>Improved the icons used by the <i>Select Language</i> dialog and the <i>Select Destination Location</i>, <i>Select Start Menu Folder</i>, and <i>Preparing to Install</i> wizard pages at 150% DPI and at 200% DPI.</li>
   <li>Added modern icons to the MyProg example executables, now compiled with Visual Studio 2022.</li>