There is no effect in calling GCC.
test.nsh:
using System; // many namespaces are loaded by default
using System.Collections.Generic;
using System.Data;
using System.Xml;
using System.Xml.Linq;
using Microsoft.CSharp;
using static System.Console; // static members smake your scripts shorter
WriteLine("Are you ready? Y/N:");
echo "Hello world"
var str="1.c";
gcc -v
run nsh:
> dotnet-shell.exe .\test.nsh
Are you ready? Y/N:
Hello world
my powershell window:(GCC has been added to the $PATH environment variables.)
>gcc -v
Using built-in specs.
COLLECT_GCC=C:\Strawberry\c\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/Strawberry/c/bin/../libexec/gcc/i686-w64-mingw32/4.9.2/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: ../../../src/gcc-4.9.2/configure --host=i686-w64-mingw32 --build=i686-w64-mingw32 --target=i686-w64-mingw32 --prefix=/mingw32 --with-gxx-include-dir=/mingw32/i686-w64-mingw32/include/c++ --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --enable-sjlj-exceptions --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=i686 --with-tune=generic --with-libiconv --with-system-zlib --with-gmp=/opt/build/prerequisites/i686-w64-mingw32-static --with-mpfr=/opt/build/prerequisites/i686-w64-mingw32-static --with-mpc=/opt/build/prerequisites/i686-w64-mingw32-static --with-isl=/opt/build/prerequisites/i686-w64-mingw32-static --with-cloog=/opt/build/prerequisites/i686-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='i686-posix-sjlj, built by strawberryperl.com project' CFLAGS='-O2 -pipe -I/opt/build/i686-492-posix-sjlj-rt_v402/mingw32/opt/include -I/opt/build/prerequisites/i686-zlib-static/include -I/opt/build/prerequisites/i686-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/opt/build/i686-492-posix-sjlj-rt_v402/mingw32/opt/include -I/opt/build/prerequisites/i686-zlib-static/include -I/opt/build/prerequisites/i686-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/opt/build/i686-492-posix-sjlj-rt_v402/mingw32/opt/lib -L/opt/build/prerequisites/i686-zlib-static/lib -L/opt/build/prerequisites/i686-w64-mingw32-static/lib -Wl,--large-address-aware'
Thread model: posix
gcc version 4.9.2 (i686-posix-sjlj, built by strawberryperl.com project)
The script didn't print the GCC information.
Second question: Why use two dollar signs ($$)? use one dollar sign ($) should be more convenient.:
var variable = "Lets say you have a variable";
// This is how you pass it into a system command
echo $variable$ ---->echo $"{variable} is 66666666"
Console.WriteLine("enter output name:")
var outFn=Console.ReadLine();
gcc -std=gnu11 main.c -o $"{outFn}.elf"
Your syntax would work fine with powershell but nothing else
The variable syntax used with an underlying shell statement is there to provide a clear delineation between csharp shell syntax and shells like bash.
In bash $x is a variable so how would these shell know to pass that through to the underlying interpreter or handle it itself? The only way is with a different syntax.
To answer your first question windows support is currently in testing. It works for a lot of things but windows support for true stout is patchy.
GCC may be writing to the console directly or has spawned another process. My current way of capturing process stout is obviously not working.
If you redirect gcc to a file does it output anything?
Your syntax would work fine with powershell but nothing else
The variable syntax used with an underlying shell statement is there to provide a clear delineation between csharp shell syntax and shells like bash.
In bash $x is a variable so how would these shell know to pass that through to the underlying interpreter or handle it itself? The only way is with a different syntax.
Since we are utilizing the C# language for scripting, I believe all variables should be defined on the C# side rather than the Bash side. This perspective is inspired by the xmake build script, where scripts are divided into a description domain and a script scope. Therefore, I propose that all variable definitions (var a=5) and logic code (if else for function class ..etc) should be handled within the C# side, which I refer to as the C# domain. Shell invocations should be limited to simple command executions, excluding any variable definitions ($var), or logic code (if, elif, fi, for, etc.). For instance:
var gcc_result=0; //C# domain
$gcc_result=gcc $"{value} is good!" //shell domain
if(gcc_result!=0) //C# domain
{ //C# domain
echo $"gcc result:{gcc_result}" //shell domain
} //C# domain
Here, I distinguish between the Shell domain and C# domain. Based on this design philosophy, encapsulating each line in the Shell domain within a process class would suffice, eliminating the need for an interpreter. If this analytical approach appears complex, an alternative syntax could be employed:
shell gcc ... // shell code line invocation
shell // shell code block
{
// Shell commands go here
}
To answer your first question windows support is currently in testing. It works for a lot of things but windows support for true stout is patchy.
GCC may be writing to the console directly or has spawned another process. My current way of capturing process stout is obviously not working.
If you redirect gcc to a file does it output anything?
no
using System; // many namespaces are loaded by default
using System.IO;
gcc -v >1.txt
1.txt 0KB. empty .
var gccTest = new Process();
gccTest.StartInfo.FileName = "gcc.exe";
gccTest.StartInfo.Arguments = " -v";
gccTest.StartInfo.RedirectStandardError = true;
gccTest.StartInfo.RedirectStandardOutput = true;
gccTest.StartInfo.RedirectStandardInput = true;
gccTest.StartInfo.UseShellExecute=false;
gccTest.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data); // 处理标准输出
gccTest.ErrorDataReceived += (sender, e) => Console.WriteLine(e.Data); // 处理标准错误
gccTest.Start();
// 开始异步读取标准输出和标准错误
gccTest.BeginOutputReadLine();
gccTest.BeginErrorReadLine();
// 在这里,你可以向进程的标准输入写入数据(如果需要的话)
// using (StreamWriter sw = process.StandardInput)
// {
// if (!process.HasExited)
// {
// sw.WriteLine("Some input data");
// }
// }
// 等待进程退出
gccTest.WaitForExit();
// 关闭异步读取
gccTest.Close();
output:
Using built-in specs.
COLLECT_GCC=gcc.exe
COLLECT_LTO_WRAPPER=C:/Strawberry/c/bin/../libexec/gcc/i686-w64-mingw32/4.9.2/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: ../../../src/gcc-4.9.2/configure --host=i686-w64-mingw32 --build=i686-w64-mingw32 --target=i686-w64-mingw32 --prefix=/mingw32 --with-gxx-include-dir=/mingw32/i686-w64-mingw32/include/c++ --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --enable-sjlj-exceptions --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=i686 --with-tune=generic --with-libiconv --with-system-zlib --with-gmp=/opt/build/prerequisites/i686-w64-mingw32-static --with-mpfr=/opt/build/prerequisites/i686-w64-mingw32-static --with-mpc=/opt/build/prerequisites/i686-w64-mingw32-static --with-isl=/opt/build/prerequisites/i686-w64-mingw32-static --with-cloog=/opt/build/prerequisites/i686-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='i686-posix-sjlj, built by strawberryperl.com project' CFLAGS='-O2 -pipe -I/opt/build/i686-492-posix-sjlj-rt_v402/mingw32/opt/include -I/opt/build/prerequisites/i686-zlib-static/include -I/opt/build/prerequisites/i686-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/opt/build/i686-492-posix-sjlj-rt_v402/mingw32/opt/include -I/opt/build/prerequisites/i686-zlib-static/include -I/opt/build/prerequisites/i686-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/opt/build/i686-492-posix-sjlj-rt_v402/mingw32/opt/lib -L/opt/build/prerequisites/i686-zlib-static/lib -L/opt/build/prerequisites/i686-w64-mingw32-static/lib -Wl,--large-address-aware'
Thread model: posix
gcc version 4.9.2 (i686-posix-sjlj, built by strawberryperl.com project)
Without the need for any interpreter!!