/// <summary> /// Writes a string result for the task that called <see cref="runWait(out string, string, string[])"/> or <see cref="runWait(Action{string}, string, string[])"/> to run this task, or for the program that started this task using command line like "Au.Editor.exe *Script5.cs". /// Returns false if this task was not started in such a way. Returns false if failed to write, except when <i>s</i> is null/"". /// </summary> /// <param name="s">A string. This function does not append newline characters.</param> /// <remarks> /// <see cref="runWait(Action{string}, string, string[])"/> can read the string in real time. /// <see cref="runWait(out string, string, string[])"/> gets all strings joined when the task ends. /// The program that started this task using command line like "Au.Editor.exe *Script5.cs" can read the string from the redirected standard output in real time, or the string is displayed to its console in real time. The string encoding is UTF8; if you use a .bat file or cmd.exe and want to get correct Unicode text, execute this before, to change console code page to UTF-8: <c>chcp 65001</c>. /// </remarks> #if true public static unsafe bool writeResult(string s) { s_wrPipeName ??= Environment.GetEnvironmentVariable("script.writeResult.pipe"); if (s_wrPipeName == null) { return(false); } if (s.NE()) { return(true); } if (Api.WaitNamedPipe(s_wrPipeName, 3000)) //15 mcs { using var pipe = Api.CreateFile(s_wrPipeName, Api.GENERIC_WRITE, 0, default, Api.OPEN_EXISTING, 0); //7 mcs if (!pipe.Is0) { fixed(char *p = s) if (Api.WriteFile(pipe, p, s.Length * 2, out _)) { return(true); //17 mcs } } } Debug_.PrintNativeError_(); return(false); //SHOULDDO: optimize. Eg the app may override TextWriter.Write(char) and call this on each char in a string etc. // Now 40 mcs. Console.Write(char) 20 mcs. }