w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
java processing input from command line
By using the st.pop() it will remove and return the last item of the stack. If you dont want it to get removed you can use one ordered Collection like ArrayList and access the item by list.get or using an Iterator. Another suggestion is to create one object to store the name and the y, x properties: class MyObject { private String name; private int x; private int y; //... setter and getter methods for the properties } Suggestion for your code: it pushes the input in the Stack, then pop the items to create the MyObject and add to the list: ArrayList listObjects = new ArrayList(); Scanner input = new Scanner(System.in); Stack st = new Stack(); while(input.hasNext()){ String tkn = input.next(); st.push(tkn); if (st.size()==3){ int

Categories : Java

Passing * as a command line argument
You need to escape the * e.g. by quoting it like "*" or by escaping it like * The expansion of * is done by the shell (before starting your program). Read e.g. the Advanced Bash Scripting guide.

Categories : C

Command line argument to string in C
What you can do is to loop over argv and build a string with strcat char* CommandLine = 0; unsigned int CommandLineLength = 0; unsigned int i = 0; for (i = 0; i < argc; i++) { CommandLineLength += strlen(argv[i]) + 3; // Add one extra space and 2 quotes } CommandLine = (char*) malloc(CommandLineLength + 1); *CommandLine = ''; // Todo: Check if allocation was successfull... for (i = 0; i < argc; i++) { int HasSpace = strchr(argv[i], ' ') != NULL; if (HasSpace) { strcat(CommandLine, """); } strcat(CommandLine, argv[i]); if (HasSpace) { strcat(CommandLine, """); } strcat(CommandLine, " "); } // Do something with CommandLine ... free(CommandLine);

Categories : C

Python - Need to get argument on command line
argparse is beautiful. Redesign your command line interface for it or write your own CLI-parser. CLI example: args = ['firstargument', 'secondargument', '-s', 'thirdargument', '-s', 'fourth', 'fifth', '-s', 'sixth'] last_arg = None container = [] marker = '-s' for arg in args: if (arg != marker): last_arg = arg else: container.append(last_arg) print container Result of execute: $python test.py ['secondargument', 'thirdargument', 'fifth']

Categories : Python

Argument treatment at command line in C
Basically, this is an issue of creating an interface between the operating system and the program. any program. Remember that programs are not always written in C, And you don't even know whether there are things like float or int in the language. You want to be able to pass several arguments (with natural delimiters), which may easily encode arbitrary information. In C, strings can be of arbitrary length, and the only constraint on them is that a zero byte in them signifies the end of the string. this is a highly flexible and natural way to pass arbitrary information to the program. So you can never supply an arbitrary integer/float arguments directly to a program; The operating system (Unix / Linux / Windows / etc.) won't let you. You don't have any tool that gives you that interface,

Categories : C

Need help on simple C command line argument
snprintf is the safest way to do this, this is a simple example without any checking of argc etc...: #include <string.h> #include <stdio.h> int main(int argc, char *argv[]) { char buf[200] ; char str1[] = "nmap -sT -p 19 "; char str2[] = " -oG - | grep 19/open > temp"; snprintf(buf, 200, "%s%s%s", str1, argv[1], str2); printf( "%s ", buf ) ;; }

Categories : C

perl optional command line argument
The arguments to a subroutine are passed in an array. It looks like you already realise that as you're building up your arguments in @args. If your subroutine is just expecting a list of arguments of arguments, then there are some problems with your approach. Firstly, as you've realised, if you push an empty array onto an array, you will get no items added on to your @args array. And that's going to confuse your subroutine. It's simple enough to test this using Data::Dumper. #!/usr/bin/perl use strict; use warnings; use 5.010; use Data::Dumper; my @arguments = ('Arg1'); my @controller; my @member; my @args; push(@args, $arguments[0]); push(@args, @controller); push(@args, @member); say Dumper @args; The output looks like this: $ ./args $VAR1 = [ 'Arg1' ]; But

Categories : Perl

Nodejs set command line argument as constant
Your init() function is executed after starter.js uses require('./start_server'). When you use require(), the file and all its dependencies are loaded. That means during this process, you also executed require('./common/loghandler'), which completes before server.init() is run in starter.js. Since server.logpath hasn't been set by this time, you get a null value. Aside from that, module.exports is set at require time and changing the values later have no effect. To fix the problems you're having, you should avoid using functions before your application has fully loaded, and put return values in your modules.

Categories : Javascript

Command Line Argument as java File
I have this Product file in same package as my main java file. That's not really relevant. Instead, you want Product.java to be in the current working directory when you run the program. (For example, if you run your program as java -jar path/to/program.jar, then you need Product.java to be in the folder that contains path.)

Categories : Java

Change a command line argument argv
Did you try debugging? If you do, you will see that it never attempts to erase anything. You can't compare strings (char*) with simple equality, because in reality you're comparing pointers, which will (almost) never be equal. Instead, you should use string comparison functions, like this: if (!strcmp(argv[i], "--item")) { Also, since you're overwriting the argument, you don't need to use a lot of spaces, you can simply set it to an empty string (argv[i] = ""), or modify the existing string to make it empty (argv[i][0] = 0). Alternatively, you could shift the rest of the arguments so you don't end up with gaps which could confuse the rest of your code.

Categories : C++

Parse command line argument using argparse
You can just add options for the arguments you don't need. parser.add_argument("-cdl-sp", dest = "sp", action='store_true') parser.add_argument("-cdl-sk", dest = "sk", action='store_true')

Categories : Python

Salt: Can I use an argument from the command line as a jinja variable?
You can do this using Pillar: packages: pkg: - installed - pkgs: {{ salt['pillar.get']('packages') }} Then pass the pillar argument containing valid YAML: salt '*' state.sls package-list pillar='{packages: [foo, bar, baz]}'

Categories : Misc

I wanted to enter a command line argument for my string
Here's a command line arguments tutorial for netbeans. Basically, you go: File->Project Properties->Run->Arguments. In your code, you should probably have: try { if (args.length != 0) { datasetFile = args[0]; in = new BufferedReader(new FileReader(datasetFile)); } } catch(FileNotFoundException e) { e.printStackTrace(); } Your question asks how to enter command line arguments, but it looks like the way you did it worked, since you got a FileNotFoundException on abc, so that's your issue.

Categories : Java

MIPS: Reading a string from command line argument
Here is a few lines of code to illistrate what you are asking: # $a0 = argc, $a1 = argv # 4($a1) is first command line argv 8($a1) is second main: lw $a0, 8($a1) # get second command line argv li $v0, 4 # print code for the argument (string) syscall # tells system to print li $v0, 10 # exit code syscall # terminate cleanly The amount of arguments is in $a0 and you could check the amount of arguments against an integer value loaded (li) into a temporary register for validation purposes. The command line argument values, argv, are stored in $a1 and can be accessed by loading the word. A word is 4 bytes and thus we can access argv[0] with 0($a1), argv[1] with 4($a1) and so forth. In this case we want arg

Categories : Assembly

Export command line argument and set it as constant for a module
the command line arguments are an array of strings called process.argv. This starts with node, then your script, then the additional arguments. To parse the actual options and flags, typically people will use a helper module. Search on npmjs.org to find one you like or implement your own. To store the value, just set it into module.exports.logPath = valueFromCommandLine;

Categories : Javascript

Command line argument as default to a function defined in another module
You can change the default by overwriting the function's func_defaults (__defaults__ in python3.x) attribute: >>> def foo(a=True): ... print a ... >>> foo() True >>> foo.func_defaults (True,) >>> foo.func_defaults = (False,) >>> foo() False >>> I don't know that I would say that this is "pythonic". As far as I'm concerned, the most pythonic solution would be to just pass the argument: import two def main(argv): opts, _ = getopt.getopt(argv, 'hs', ['--strict=']) for opt, _ in opts: if opt in ('-s', '--strict'): config.strict = True two.foo(s=config.strict)

Categories : Python

How to pass dictionary as command line argument to python script?
Check this: >>> from sys import argv >>> from re import findall >>> args = ' '.join(argv[1:]) >>> pattern = r'([^=]+)s*=s*[s*([^]]+)s*]' >>> d = dict((t[0].strip(), map(lambda x: x.strip(', '),t[1].split())) for t in findall(pattern,args)) >>> for k,v in d.items(): try: d[k] = map(int,v) except: pass >>> d {'names': ['"J.J."', '"April"'], 'years': [25, 29]}

Categories : Python

How to escape a variable in bash when passing to command line argument
You need escaped double quoted marks when providing destinationPath in a string. This should work: #!/bin/sh # file paths destinationPath="/cygdrive/c/Documents and Settings/Eric/My Documents/" attachments=" 2013-12-12.pdf" body="Test Body" recipient="asdf@asdf.com" # prepare attachments args="" for file in $attachments ; do file=${file//[ \n]/} touch $file mv $file "$

Categories : Bash

OpenCV using command line argument for input image (Python)
In python and most other languages argv[0] contains the program name. Try using argv[1] to get the correct result. Here is some Python Documentation to help you. Python has an amazing library of documentation I highly recommend using it.

Categories : Python

Python command line argument semicolon-loop error
If you're writing it in a script, why don't you indent it just the way you would do it in a real python program? Like this: python -mtimeit " n = 0 while n < 10: pass"

Categories : Python

Maximum string length that can be passed in command line argument?
You might modify the C++ and PHP sources and build a pipe. C++ int main () { std::ostringstream txt; txt << std::cin.rdbuf(); std::cout << "Input: " << txt.str() << std::endl; return 0; } PHP <?php $pipe = popen('Debug/Test', 'w'); if( ! $pipe) { // Error } else { $txt = 'Hello World'; fwrite($pipe, $txt, strlen($txt)); pclose($pipe); } ?>

Categories : C++

How to pass argument in expect through command line in shell script
If you want to read from arguments, you can achieve this simply by set username [lindex $argv 0]; set password [lindex $argv 1]; And print it send_user "$username $password" That script will print $ ./test.exp user1 pass1 user1 pass1 You can use Debug mode $ ./test.exp -d user1 pass1

Categories : Linux

compare a command line argument with or statment to different strings python
How about using in? if protocol not in ("tcp", "udp"): print" error" sys.exit() FYI, instead of using sys.argv and validating script arguments manually, use argparse module from stdlib. Take a look at choices argument of add_argument method, docs: choices - A container of the allowable values for the argument.

Categories : Python

libnet device (Network interface) command line argument
I was confused by the same problem. It can be solve like this. in lib wpcap there is a function named pcap_findalldevs(); use it like this and you will succuss int Value = pcap_findalldevs(&alldevs,errbuf); if( Value == -1) { fprintf(stderr,"Error in pcap_findalldevs: %s ", errbuf); exit(1); } char *device = NULL; device = alldevs->name; //get the first Card name libnet_t *l l = libnet_init( LIBNET_LINK_ADV, device,//use it here error_information); may this help you. good luck!

Categories : Windows

How to pass special character ('-' for example) as an argument in command line in windows?
I do not think you are right. For PuTTY, a dash (minus) does not have any special meaning, unless it is after a whitespace character. So for your example in the question, PuTTY will use password password-passwordend. While I would not actually expect this, it may be your SSH server that misinterprets dashes in the password.

Categories : Windows

Using windows command line to run python script with passing of url argument
I think the problem is the way you specify your url, it needs to have the http:// part at the start. It works for me when I type python sys.py http://www.google.com/ but fails with python sys.py www.google.com (Note that I am using linux with python 2.7 but I think it may be the same problem for you)

Categories : Windows

Python argparse: command-line argument that can be either named or positional
Try to use the "nargs" parameter of the add_argument methode. This way it works for me. Now you can add the username twice, so you have to check it and raise an error, if you want. import argparse if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("-u", "--user-name", default="admin") parser.add_argument("user_name", default="admin", nargs="?") args = parser.parse_args() print(args)

Categories : Python

How to supply command line argument to perl script through Java
If you don't want to add another command line argument to your script (which is much cleaner and more robust) you need to write to the script's stdin. This snippet should work (Test.java): import java.io.*; public class Test { public static void main(String[] args) { ProcessBuilder pb = new ProcessBuilder("perl", "test.pl"); try { Process p=pb.start(); BufferedReader stdout = new BufferedReader( new InputStreamReader(p.getInputStream()) ); BufferedWriter stdin = new BufferedWriter( new OutputStreamWriter(p.getOutputStream()) ); //write to perl script's stdin stdin.write("testdata"); //assure that that the data is written and does not

Categories : Java

How to pass Command line argument to specflow test scenario
Specflow doesn't provide any mechanism to do this. While I can see why you might think you want to do this, be careful to consider what is going to happen by linking your tests to an external dependency such as the service that you are going to connect to. While you will have built yourself a means of automating a set of tests, there will be many reasons why they fail. For example, servers not running, configuration not being vaild or even differences in version of client and server. Personally in instances where I have wanted to test the full regression of interprocess communication I have hosted both the client and the server in my tests so that I can more easily control that they start and stop both parts. Even then these tests are very flaky compared with tests that cut out the commu

Categories : C#

Boost::Program_options, passing an unknown command line argument
You should remove allow_unregistered() from your parse command. You command should simply be po::store(parse_command_line(argc, argv, desc), vm); then exception will be thrown on unknown options. http://www.boost.org/doc/libs/1_54_0/doc/html/program_options/howto.html#idp123440592 If you want exception/error, if option has no "--" you should write extra parser, something like this, can help you std::pair<std::string, std::string> fix_option(const std::string& value) { std::string name = value; std::string val; std::string::size_type pos = name.find("="); if (pos != std::string::npos) { val = name.substr(pos + 1); name = name.substr(0, pos); } if (name.substr(0, 2) != "--") { throw std::logic_error(std::string("invalid command, no --

Categories : C++

Passing each line of a file as command line argument to a binary file
Something this simple would normally be best handled by a "scripting" language, but it's pretty straight foreward in C++ as well. If you're reading your file from standard in: std::string args; while ( std::getline( std::cin, args ) ) { system( ("temp " + args).c_str() ); } should be all you need. (But you don't say what you want to do if temp fails.)

Categories : C++

Passing a command line argument to Python whos string contains a metacharacter
As you said yourself, Python only sees the strings after being processed by the shell. The command-line arguments '-f' and -f look identical to the called program, and there is no way to dsitinguish them. That said, I think that argparse supports a -- argument to denote the end of the options, and everything after this is treated as a positional argument.

Categories : Python

how to retrieve array variable elements passed as a command line argument to Expect script
The expect global variable $argv is a list (i.e. a perl array). If you want to capture it in a different variable: set myvar $argv Or use it directly foreach item $argv { do something with $item }

Categories : Perl

Flyway command line filesystem migrations from actual command line input
flyway.cmd -configFile=/path/to/other/configFile.conf should do what you want. I just checked and it seems I forgot to document this on the website (It is in the usage description of the tool itself). Could you file an issue against the website, requesting this to be added?

Categories : Windows

How to give o/p of one command to the argument of another command in shell script?
As per what i think the below code should satisfy your need. I only gave a dry run to it. Store the result in a variable and then looping to extract data one by one #! /bin/bash $op = find ./kernel -name *.ko" for zf in $op do cp -rpf $zf tail $zf done

Categories : Linux

Piping output from 1 command to other command in an adb shell command line
One way is to create a shell script containing the commands you want and then run the shell script. Since the Android root filesystem is not writeable at run time (usually, unless you have rooted your device and remount it), you can copy the file to the removable (or emulated) storage, for example /sdcard. Then run the script using the command adb shell sh /sdcard/your-script-name. Because each script runs in its own subshell, both of your commands will be executed in the same shell on the device (you can confirm it with ps).

Categories : Android

Warning: array_merge(): Argument #1 is not an array, when processing two $_POST
That's because $cp is a string (you explicitly defined it that way). $cp = ''; // <-- empty string $cp = array_merge($cp, $_POST['cpl']); should be: $cp = array(); // <--now it's an array $cp = array_merge($cp, $_POST['cpl']);

Categories : PHP

AngularJS inner ng-repeat not processing $index.$parent in function argument
First let me point out that ng-repeat creates new scope. Also, I'm assuming that the outer repeat does not sit inside yet another repeat. Assuming that, notice in your first example that you pass $index to the selectedNodeAtLevel function. This works because $index is defined by the outer repeat and parsed in the context of the scope of the outer repeat. This $index variable corresponds to each nodeName. So the second example fails because there is no $index defined in the outer repeat's $parent (which actually refers to the scope of the controller this code sits in). In at least the second case, it seems that you expect that $index refers to the inner repeat, but it does not, it refers to the $index defined in the already defined scope. So you should have issues even in your first ex

Categories : Angularjs

unix command line cut and remove new line, unwrap next line
This awk one liner can do it: $ awk '{if ($0 ~ /&$/) {getline a; print $0,a} else {print }}' file it gets the lines ending with & and joins them with the next one. Otherwise just prints the line. Test $ awk '{if ($0 ~ /&$/) {getline a; print $0,a} else {print }}' file A7233334 PALLETS 2 11.000 EACH 2331 Storm Supply 247.5000 2,722.50 2,722.50 4144 Gentro Sales 225.0000 2,475.00 2,475.00 5155 Wacca Outfit 225.0000 2,475.00 2,475.00 6661 Acme Warehouse & Fuller Supply 225.0000 2,475.00 2,475.00 1661 McHugh & Donaldson

Categories : Unix

Command works in command line but gives 'no such file or directory' in bash script
Remove the quotes around line 8. Like this: ./optAlg.exe "$inputFile" 500 2>&1 > "output/$outputFile" By placing quotes around the whole line you tell bash to execute a command which is called exactly ./optAlg.exe $inputFile 500 2>&1 > output/$outputFile and of course there is no such command. In reality you want to run ./optAlg.exe with parameters. Do not forget to place quotes around the variables because otherwise filenames that have whitespace characters are going to be passed as several arguments. Please read about arguments. And you can read about common pitfalls as well.

Categories : Bash



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.