command-line-arguments

Script Argument matching

二次信任 提交于 2021-01-27 07:16:08
问题 Does PowerShell do some sort of nearest match or autocompletion when dealing with arguments passed to a script? Given this code... [CmdletBinding()] Param( [string][Alias("aS")] $applySet, [string][Alias("cS")] $conformSet, [string][Alias("sL")] $setList, [Parameter(ValueFromRemainingArguments = $true)][Object[]]$extraParameters = @() ) Write-Host "s: $set" Write-Host "sL: $setList" Write-Host "aS: $applySet" Write-Host "cS: $conformSet" Write-Host "X: $extraParameters" If I use -junk "junk"

Script Argument matching

这一生的挚爱 提交于 2021-01-27 07:14:57
问题 Does PowerShell do some sort of nearest match or autocompletion when dealing with arguments passed to a script? Given this code... [CmdletBinding()] Param( [string][Alias("aS")] $applySet, [string][Alias("cS")] $conformSet, [string][Alias("sL")] $setList, [Parameter(ValueFromRemainingArguments = $true)][Object[]]$extraParameters = @() ) Write-Host "s: $set" Write-Host "sL: $setList" Write-Host "aS: $applySet" Write-Host "cS: $conformSet" Write-Host "X: $extraParameters" If I use -junk "junk"

Getting raw (unsplit) command line in .NET

前提是你 提交于 2021-01-07 01:31:24
问题 In .NET, we can easily access split command line arguments in a string array from the argument of Main(string[]) or Environment.GetCommandLineArgs() . However, is there a way to get the unparsed command line as one string? Background: my app is adding itself to FileExplorer context menu (like Notepad++ does). When it's launched this way, the filename is passed in without quoting, which means if there are spaces in the path, it's broken down. I know I can fix this by embrace %1 in quotation

Escape sequences in command line arguments (Java)

…衆ロ難τιáo~ 提交于 2021-01-01 04:30:23
问题 According to How to use line break argument When you define a String as "Hello\nHello" in Java, it contains no '\' character. It is an escape sequence for the line break: "\n" is just one character. When you use this string as an argument to your program, however (so the string is defined outside), "\n" is interpreted as two characters: '\' and 'n'. Why won't the command line arguments containing escape sequences be compiled as well? I thought the command line arguments are placed into the

Escape sequences in command line arguments (Java)

随声附和 提交于 2021-01-01 04:30:08
问题 According to How to use line break argument When you define a String as "Hello\nHello" in Java, it contains no '\' character. It is an escape sequence for the line break: "\n" is just one character. When you use this string as an argument to your program, however (so the string is defined outside), "\n" is interpreted as two characters: '\' and 'n'. Why won't the command line arguments containing escape sequences be compiled as well? I thought the command line arguments are placed into the

Python argparse allow combined flags

天涯浪子 提交于 2020-12-24 12:36:05
问题 Is it possible for argparse to parse combined flags like this: app.py -bcda something In this case, I would want something to be set to -a and the rest would be stored True. Basically: app.py -b -c -d -a something I know most programs allow this, e.g. grep -rEw , but how hard would it be to do this with with argparse? Edit: The answer is that it comes out-of-the-box. I didn't even bother to try it. 回答1: You can achieve this with store_const: parser = argparse.ArgumentParser() parser.add

When implementing command line flags, should I prefix with a fowardslash (/) or hyphen (-)?

独自空忆成欢 提交于 2020-12-04 20:01:23
问题 Are their any conventions (either written or just generally understood) for when to use a forward slash (/) or a hyphen (-) when reading arguments/flags from a command line? C:\> myprogram.exe -a C:\> myprogram.exe /a The two seem to be interchangeable in my experience, but I haven't used enough command line tools to say I've spotted any rules or patterns. Is there a good reason that either of them are used at all? Could I theoretically use an asterisk (*) if I wanted to? 回答1: You can

Pass arguments from cmd to python script

此生再无相见时 提交于 2020-11-27 01:34:28
问题 I write my scripts in python and run them with cmd by typing in: C:\> python script.py Some of my scripts contain separate algorithms and methods which are called based on a flag. Now I would like to pass the flag through cmd directly rather than having to go into the script and change the flag prior to run, I want something similar to: C:\> python script.py -algorithm=2 I have read that people use sys.argv for almost similar purposes however reading the manuals and forums I couldn't

Pass arguments from cmd to python script

时光毁灭记忆、已成空白 提交于 2020-11-27 01:33:55
问题 I write my scripts in python and run them with cmd by typing in: C:\> python script.py Some of my scripts contain separate algorithms and methods which are called based on a flag. Now I would like to pass the flag through cmd directly rather than having to go into the script and change the flag prior to run, I want something similar to: C:\> python script.py -algorithm=2 I have read that people use sys.argv for almost similar purposes however reading the manuals and forums I couldn't

Pass arguments from cmd to python script

心不动则不痛 提交于 2020-11-27 01:33:50
问题 I write my scripts in python and run them with cmd by typing in: C:\> python script.py Some of my scripts contain separate algorithms and methods which are called based on a flag. Now I would like to pass the flag through cmd directly rather than having to go into the script and change the flag prior to run, I want something similar to: C:\> python script.py -algorithm=2 I have read that people use sys.argv for almost similar purposes however reading the manuals and forums I couldn't