Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shorthand for running external commands #526

Closed
mungojam opened this issue Mar 14, 2020 · 1 comment
Closed

Shorthand for running external commands #526

mungojam opened this issue Mar 14, 2020 · 1 comment

Comments

@mungojam
Copy link

mungojam commented Mar 14, 2020

I'd like to replace some simple powershell scripts with dotnet-script so that I can expand them using C# syntax. The scripts execute some external exes, which in powershell is very succinct and similar to a simple batch file, but with C# the most succinct seems to be Process.ExecuteAsync which is still harder for others to follow than a simple call to the exe with all it's arguments.

I wonder if there could be a new magic command to do it, something like:

#run xcopy C:\somefolder E:\backupfolder /D /E /C /R /H /I /K /Y

compared with how it would currently look:

using System.CommandLine.Invocation;

await Process.ExecuteAsync("xcopy", @"""C:\some folder"" E:\backupfolder /D /E /C /R /H /I /K /Y");

I guess I could simplify it a bit by making a shared script that took a single string as an Arg and split it to run Process.ExecuteAsync

@mungojam
Copy link
Author

Thinking about it, I realised that the # commands are actually pre-processor commands so it wouldn't really work to have them as special commands in the middle of C# (and might look a bit odd!). I've also realised that the ExecuteAsync command doesn't make you put the command line parameters as completely separate parameters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant