C
C#8mo ago
AJ

❔ Trying to run a command through C# on macOS

I'm currently utilising Jetbrains rider. My tutor has tasked me with creating a simple little C# transpiler, that will have source code, which works and builds into a CS file, after that it then needs to compile via Mono. Everything works except trying to get the csc build.cs file working.
void Build()
{
...
Compile($"csc {buildDir}/build.cs");
}

void Compile(string command)
{
Process.Start("csc", command);
Environment.Exit(0);
}
void Build()
{
...
Compile($"csc {buildDir}/build.cs");
}

void Compile(string command)
{
Process.Start("csc", command);
Environment.Exit(0);
}
5 Replies
Pobiega
Pobiega8mo ago
you're specifying csc twice this will equate to running csc csc build/build.cs in the terminal
AJ
AJ8mo ago
I see so i really should be doing Process.Start(command); @Pobiega ? When doing that:
Unhandled exception. System.ComponentModel.Win32Exception (2): An error occurred trying to start process 'csc /Users/myname/Documents/CascTest/build.cs' with working directory '/Users/myname/Documents/Rider/Cascscript/Cascscript/bin/Debug/net7.0'. No such file or directory
at System.Diagnostics.Process.ForkAndExecProcess(ProcessStartInfo startInfo, String resolvedFilename, String[] argv, String[] envp, String cwd, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at Program.<<Main>$>g__Compile|0_3(String command) in /Users/myname/Documents/Rider/Cascscript/Cascscript/Program.cs:line 269
at Program.<<Main>$>g__Build|0_2(<>c__DisplayClass0_0&) in /Users/myname/Documents/Rider/Cascscript/Cascscript/Program.cs:line 263
at Program.<Main>$(String[] args) in /Users/myname/Documents/Rider/Cascscript/Cascscript/Program.cs:line 232
Unhandled exception. System.ComponentModel.Win32Exception (2): An error occurred trying to start process 'csc /Users/myname/Documents/CascTest/build.cs' with working directory '/Users/myname/Documents/Rider/Cascscript/Cascscript/bin/Debug/net7.0'. No such file or directory
at System.Diagnostics.Process.ForkAndExecProcess(ProcessStartInfo startInfo, String resolvedFilename, String[] argv, String[] envp, String cwd, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at Program.<<Main>$>g__Compile|0_3(String command) in /Users/myname/Documents/Rider/Cascscript/Cascscript/Program.cs:line 269
at Program.<<Main>$>g__Build|0_2(<>c__DisplayClass0_0&) in /Users/myname/Documents/Rider/Cascscript/Cascscript/Program.cs:line 263
at Program.<Main>$(String[] args) in /Users/myname/Documents/Rider/Cascscript/Cascscript/Program.cs:line 232
Pobiega
Pobiega8mo ago
no you should remove the csc from the command you are generating the first argument to process.start is the command itself, not any arguments
AJ
AJ8mo ago
Oh don’t think of that x Ty
Accord
Accord8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.