simeneilevstjonn / TeamsTeX

Rendering of LaTeX content in Microsoft Teams
MIT License
0 stars 0 forks source link

Issues with running Docker commands #2

Open aidev123 opened 1 month ago

aidev123 commented 1 month ago

Is there any prior Docker setup that needs to be done to run the code?

I have been experiencing the following error: {System.ComponentModel.Win32Exception (2): An error occurred trying to start process '/bin/rm' with working directory 'C:\Users\U2\Desktop\AI'. The system cannot find the file specified. at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start(String fileName, String arguments) at LaTeXForTeamsApp.LatexRenderer.LatexToSvg(String latex) in C:\Users\U2\Desktop\AI\LatexRenderer.cs:line 54 at LaTeXForTeamsApp.LatexRenderer.LatexToPngString(String latex) in C:\Users\U2\Desktop\AI\LatexRenderer.cs:line 84 at Program.<>c__DisplayClass0_2.<<

$>b__9>d.MoveNext() in C:\Users\U2\Desktop\AI\Program.cs:line 253

The error seems to be stemming from the process run by Docker commands in the following code: // Compile latex
try { Process docker = Process.Start("/usr/bin", $"docker run --rm -i -v {string.Format("{0}/{1}", WorkDir, id)}:/data --net=none blang/latex /bin/bash -c \"{DockerCommands}\""); await docker.WaitForExitAsync(); } catch { // Cleanup Process delp = Process.Start("/bin/rm", string.Format("-rf {0}/{1}", WorkDir, id)); await delp.WaitForExitAsync(); throw new LatexException(); }

simeneilevstjonn commented 1 month ago

The program is trying to run /usr/bin/sudo and /bin/rm. These do not exist on Windows. There could probably have been a check for the host OS in LatexRenderer.cs.

You could probably try to remove /usr/bin/sudo in the first call to make it run on Windows. I.e.

 Process docker = Process.Start($"docker run --rm -i -v {string.Format("{0}/{1}", WorkDir, id)}:/data --net=none blang/latex /bin/bash -c \"{DockerCommands}\"");

In a previous version, f5bd195, the file deletion was done using PowerShell.

Process delp = Process.Start("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", string.Format("rm -R {0}/{1}", WorkDir, id));

This is not tested, so there is no guarantee that it will work.