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.
Related
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
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?
I am running an inherited project written in C# inside Visual Studio Code. In order for this application to run, it needs to take command line input (-t, -h, etc). How do I test this from inside Visual Studio?
Currently (I've been learning dotnet, C#, VS, etc as I go) I have a hello world program I can run from vsc's terminal. For a reason I haven't been able to pinpoint, probably how I installed it, dotnet run isn't recognized - I have to feed it an explicit path to dotnet.exe: C:\Program Files\dotnet\dotnet.exe run
How can I do this when the program requires command line input? My shot in the dark of C:\Program Files\dotnet\dotnet.exe run -t predictably didn't work, but I'm not sure what else to try.
Thanks!
If you are using dotnet.exe run to start your application you need add the -- switch statement to instruct dotnet.exe to pass the arguments to your application. For example
Microsoft Documentation
dotnet.exe run -- -arg1 -arg2 (etc) notice the -- after the dotnet arguments and before your program specific arguments.
GitHub Issue
Run with Terminal
When you run your code using terminal you must add ' -- ' to tell dotnet you are running your code with an argument/s
C:>dotnet run -- <your arguments here>
Run with Debugger
Locate your .vscode folder inside your project if not create one.
Open the launch.json file
You will see a json object and add your arguments inside the "args" key.
launch.json
"configurations": [
{
"name": ".NET Core Launch (console)",
"args": [], // PUT YOUR ARGUMENTS HERE
...
}
]
I tried to add a comment to Nico's answer but I lack sufficient reputation points. I was confused by the dash character in front of each arg: "-arg1 -arg2 (etc)". For clarity I would like to point out that .NET Core 2.1 seems to not need this. In the case of my console app, it takes a date for the first arg, an integer for the second, then an operator (+ or -) for the third arg. If I entered the following:
C:\>dotnet run -- -7/13/2018 -30 -+
I found that the leading dash in front of each arg was passed into the program along with the intended arg and I ended up trying to date parse "-7/13/2018"
I got the expected result when I entered it like this:
C:\>dotnet run -- 7/13/2018 30 +
Since OP is specifically asking about how to do this in Visual Studio Code, they are likely using VSCode's run feature (not the dotnet CLI as other answers assume), to run their application. In this case, the proper way to supply command line arguments is via the .vscode\launch.json file.
Add an args array attribute to your configuration and populate it with the arguments you would like to pass.
"configurations": [
{
// ... ,
"args": ["-arg1", "-arg2"]
}
Right click on your project
Click Properties
Click Debug in the Properties window
Under "start options:"
Add a "Command Line Argument:" = run -t
Add a "Working Directory:" try the bin\debug directory
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.
I am running an inherited project written in C# inside Visual Studio Code. In order for this application to run, it needs to take command line input (-t, -h, etc). How do I test this from inside Visual Studio?
Currently (I've been learning dotnet, C#, VS, etc as I go) I have a hello world program I can run from vsc's terminal. For a reason I haven't been able to pinpoint, probably how I installed it, dotnet run isn't recognized - I have to feed it an explicit path to dotnet.exe: C:\Program Files\dotnet\dotnet.exe run
How can I do this when the program requires command line input? My shot in the dark of C:\Program Files\dotnet\dotnet.exe run -t predictably didn't work, but I'm not sure what else to try.
Thanks!
If you are using dotnet.exe run to start your application you need add the -- switch statement to instruct dotnet.exe to pass the arguments to your application. For example
Microsoft Documentation
dotnet.exe run -- -arg1 -arg2 (etc) notice the -- after the dotnet arguments and before your program specific arguments.
GitHub Issue
Run with Terminal
When you run your code using terminal you must add ' -- ' to tell dotnet you are running your code with an argument/s
C:>dotnet run -- <your arguments here>
Run with Debugger
Locate your .vscode folder inside your project if not create one.
Open the launch.json file
You will see a json object and add your arguments inside the "args" key.
launch.json
"configurations": [
{
"name": ".NET Core Launch (console)",
"args": [], // PUT YOUR ARGUMENTS HERE
...
}
]
I tried to add a comment to Nico's answer but I lack sufficient reputation points. I was confused by the dash character in front of each arg: "-arg1 -arg2 (etc)". For clarity I would like to point out that .NET Core 2.1 seems to not need this. In the case of my console app, it takes a date for the first arg, an integer for the second, then an operator (+ or -) for the third arg. If I entered the following:
C:\>dotnet run -- -7/13/2018 -30 -+
I found that the leading dash in front of each arg was passed into the program along with the intended arg and I ended up trying to date parse "-7/13/2018"
I got the expected result when I entered it like this:
C:\>dotnet run -- 7/13/2018 30 +
Since OP is specifically asking about how to do this in Visual Studio Code, they are likely using VSCode's run feature (not the dotnet CLI as other answers assume), to run their application. In this case, the proper way to supply command line arguments is via the .vscode\launch.json file.
Add an args array attribute to your configuration and populate it with the arguments you would like to pass.
"configurations": [
{
// ... ,
"args": ["-arg1", "-arg2"]
}
Right click on your project
Click Properties
Click Debug in the Properties window
Under "start options:"
Add a "Command Line Argument:" = run -t
Add a "Working Directory:" try the bin\debug directory