Editor/BuildSettings.cs
/// <summary>
/// Executes the batch file at the given address with given arguments.
/// </summary>
/// <param name="batchFile">Address of the batch file to be executed.</param>
/// <param name="arguments">Arguments to pass to the batch file.</param>
/// <returns>True if the batch file was executed successfully.</returns>
Executes the batch file at the given address with given arguments.
Executes the batch file at the given address with given arguments .
private static bool ExecuteBatchFile(string batchFile, params string[] arguments)
        {
            try
            {
                var separator = Path.DirectorySeparatorChar;
                var folders = Application.dataPath.Split(separator, Path.AltDirectorySeparatorChar).ToList();
                folders.RemoveAt(folders.Count - 1);
                var assetsPath = string.Join(separator.ToString(), folders);
                batchFile = $"{assetsPath}/{batchFile}".Replace(separator, Path.AltDirectorySeparatorChar);
                var args = string.Join(" ", arguments);
                Process process = Process.Start(batchFile, args);
                while (true)
                {
                    process.Refresh();
                    if (EditorUtility.DisplayCancelableProgressBar("Executing batch file", batchFile, 0.5f))
                    {
                        process.Kill();
                        break;
                    }
                    if (process.HasExited)
                        break;
                }
                EditorUtility.ClearProgressBar();
                if (process.ExitCode != 0)
                {
                    Debug.LogError($"Error while executing '{batchFile}'! Exit code: {process.ExitCode.ToString()}.");
                    return false;
                }
            }
            catch (Exception e)
            {
                Debug.LogError($"Error while executing '{batchFile}'! ERROR:\n<color=red>{e}</color>.");
                return false;
            }
            Debug.Log($"'{batchFile}' executed successfully");
            return true;
        }
private static bool ExecuteBatchFile ( string batchFile , params string [ ] arguments ) { try { var separator = Path . DirectorySeparatorChar ; var folders = Application . dataPath . Split ( separator , Path . AltDirectorySeparatorChar ) . ToList ( ) ; folders . RemoveAt ( folders . Count - 1 ) ; var assetsPath = string . Join ( separator . ToString ( ) , folders ) ; batchFile = $" { assetsPath } / { batchFile } " . Replace ( separator , Path . AltDirectorySeparatorChar ) ; var args = string . Join ( " " , arguments ) ; Process process = Process . Start ( batchFile , args ) ; while ( true ) { process . Refresh ( ) ; if ( EditorUtility . DisplayCancelableProgressBar ( " " , batchFile , 0.5f ) ) { process . Kill ( ) ; break ; } if ( process . HasExited ) break ; } EditorUtility . ClearProgressBar ( ) ; if ( process . ExitCode != 0 ) { Debug . LogError ( $" Error while executing ' { batchFile } '! Exit code:  { process . ExitCode . ToString ( ) } . " ) ; return false ; } } catch ( Exception e ) { Debug . LogError ( $" Error while executing ' { batchFile } '! ERROR: \n <color=red> { e } </color>. " ) ; return false ; } Debug . Log ( $" ' { batchFile } ' executed successfully " ) ; return true ; }
Executes the batch file at the given address with given arguments.
Executes the batch file at the given address with given arguments .
True if the batch file was executed successfully.
True if the batch file was executed successfully .
batchFile
string
Address of the batch file to be executed.
Address of the batch file to be executed .
arguments
Arguments to pass to the batch file.
Arguments to pass to the batch file .