Passing arguments to 'open' command in MACOS - c#

I have an application in .NET Core and I have to run it using script.
First I thought that I have to have virtual Windows to open few instanses of my application. I had bat scripts with that command:
start ./Host/bin/Release/netcoreapp3.1/win-x64/Host.exe "./CONFIG/host1.json"
And now I found that I can create OSX Executable files using command:
dotnet publish -r osx-x64 -c Release
So now I can use Macos Terminal to start application
open ./Host/bin/Release/netcoreapp3.1/osx-x64/Host --args "./CONFIG/host1.json"
BUT I have to pass an argument to Main application and open command doesn't want to pass by my string.
I've tried with open -a Terminal ... or ... --args './CONFIG/host1.json'.
My Host application is opened but args[0] in main is empty.
How can I pass properly my string argument?

Related

C# run a .bat file where some of the commands are to be run in an attached linux shell

I am able to execute a .bat file with these commands contained:
ssh -i BatchStagingVM_key.pem azureuser#xx.xxx.xx.xx //works
timeout /T 5 /NOBREAK
echo blah
Essentially the first one runs, connecting to the VM, but the last two does not even register or get to the shell in the logged into linux vm command line. there is a few questions relating to executing .bat files, but none where some of the commands are to be executed on a vm on that same command line instance. Running these one at a time, works fine, but I want to automate this. Any advice/ideas/packages to check out?
The linux VM command line, that isn't receiving commands from the .bat file execution

C# - What can I do to run the scripts in my .bat file, when bat is called using ProcessStartInfo()?

I have a web application created using .net core 2. In the application, I have a backup feature. When button is clicked, the application will call the bat file with parameters using ProcessStartInfo().
Everything is okay in the development week, I don't encounter any errors and my .bat file is doing everything it is told to do. But when I deployed the project into the production server, it seems almost all of the command inside the .bat file is not working at all.
I have two windows computers. I deployed the project in computer2 in IIS. Then I access the project in my computer1. I developed the project in computer1. Note that the application have web and api projects.
Here is the folder structure of computer2:
C:\Project\
|-- api\
|-- web\
|--script\Backup.bat
the WEB is calling the API, then API is calling the Backup.bat by:
ProcessStartInfo info = new ProcessStartInfo(#"C:\Project\script\Backup.bat", "param1"));
var process = Process.Start(info);
process.WaitForExit();
the following commands inside the Backup.bat is not working:
xcopy /S /I C:\data1 C:\backup\data1
SQLCMD -S .\SQLEXPRESS -U root -P root -Q "Backup Database myDatabase To Disk='C:\backup\myDatabase.bak'"
but other commands like MOVE, ECHO, MKDIR is working properly.
It only won't work, when called using the web app, but when called from command prompt it is working properly.
Also I made it work by adding START command before xcopy and SQLCMD, sample is: START XCOPY /S /I .... and START SQLCMD ....
but is it possible to make it work without start command? The start command opens new prompt and I don't want that.
My question is, how can I make my .bat file work in production server as it worked in my development's? Thanks!

Get Command used to run Process

In a C program in Linux, I can use the first argument to get the command that was used to run a process. Is there a way to do something similar for C#?
For example, if I use dotnet run/dotnet to run the program or double-click a published executable, is it possible to retrieve that programmatically (dotnet run, dotnet <…>.dll, or <executable path>)?
I can get the DLL/EXE that is running with System.Reflection.Assembly.GetExecutingAssembly().Location, but that doesn't help much when the user is running the project directly with dotnet run instead of dotnet <…>.dll.
You can use the Environment.CommandLine property to get the command line for the current program. Note that in the case of dotnet run myassembly.exe, the dotnet run part is dropped. E.g. if the command line is dotnet run myassbembly.exe foo bar, the Environment.CommandLine property will contain myassembly.exe foo bar.

How I can run my NUnit test with Selenium WebDriver using MSBuild + bath?

I have a few simple NUnit tests with Selenium WebDriver in my VS. How I can run my tests in console using MSBuild + batch? I create .bat file the following:
set pathMSBuild = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\"
#echo off
cls
cd %pathMSBuild%
msbuild.exe "C:\Users\IliA\Documents\Visual Studio 2015\Projects\GitHubAutomation\GitHubAutomation.sln" /p:configuration=debug
pause
But when I try to run build.bat I have an error: 'msbuild' is not recognized as an internal or external command, operable program or batch file.
My build.bat is situated in a C:\
To enable msbuild in Command Prompt, pls add .Net(version) framework location to the PATH environment variable.
Environment variables can be accessed by right clicking on 'Computer', select 'properties', click 'Advanced system settings' on the left nav. In the dialog box click 'Environment variables' button and update 'PATH'with .Net framework path for e.g. C:\Windows\Microsoft.NET\Framework\v4.0.30319.
or
Update your bat file to CD into .Net framework directory where msbuild.exe is available and then issue msbuild <prj> command as shown below:
CD C:\Windows\Microsoft.NET\Framework64\v4.0.30319
msbuild <<YOUR PROJECT PATH>>
PAUSE
EXIT

Run Mono App on startup in Ubuntu with "startup applications"

Relative to same problem of Run Mono Application on Startup with Upstart, here this something that I don't understand:
In "startup applications", (1) I added a new program (Terminal) with the command:
gnome-terminal
Ok, the terminal opens on Ubuntu startup. (2) Then I changed the command to:
gnome-terminal -e nano /home/user/Documents/test.txt
Ok, the terminal opens with nano editor. (3) Then I changed the command to:
gnome-terminal -e /usr/bin/mono /usr/lib/IndsysAndon/IndsysAndon.exe
And the terminal opens and closes after 1 second, without run de application.
But, when I pastes the command of (3) in a terminal opened in (1), the application runs. Why this happens? Is needed a time to load all dependencies in startup? Thanks
gnome-terminal expects the command to execute, along with any arguments, as a single string passed via the -e option.
If you write
gnome-terminal -e foo bar
then the command to run will be foo and the bar will be considered an argument to gnome-terminal itself. (Remember that options can appear in any order.)
If you want to pass arguments to the command, you will need to make sure they are passed as a single string to gnome-terminal. You can do that by quoting:
gnome-terminal -e "foo bar"
Unfortunately gnome-terminal doesn't use a more user-friendly way, where any subsequent arguments after the command would automatically be considered arguments to the program and not to gnome-terminal.

Categories