working on it ...

Filters

Explore Public Snippets

Sort by

Found 73 snippets matching: argv

    public by lbottaro  2183  0  8  0

    How to check the presence of argv parameter in python

    This script checks the parameters passed via command line. If the parameter is present a check on its value and cast are performed. The script handles exception as well.
    #!/usr/bin/python
    
    import sys
    
    # ------------------------------- Main program -------------------------------
    
    # The default value for command line argv parameter
    default_size = 70
    actual_value = default_size
    
    if (len(sys.argv) > 1):
        try:
            if(int(sys.argv[1]) > 0):
                actual_value = int(sys.argv[1])
                print "Actual size: " + str(actual_value)
            else:
                print("Please specify only positive integer as parameter! " + str(sys.argv[1]))
                print("Actual size set with default value: " + str(actual_value))
        except Exception:
            print("Ouch!... Please review the parameter! " + str(sys.argv[1]))
            sys.exit(-1)
    
    

    external by QuillyT  115  0  2  0

    Playing with console arguments# This is going to show you what the ARGV values do variable = ARGV p variable puts ARGV[0] puts ARGV[1] puts ARGV[2] thing = (ARGV[7] == nil) puts thing.inspect

    Playing with console arguments# This is going to show you what the ARGV values do variable = ARGV p variable puts ARGV[0] puts ARGV[1] puts ARGV[2] thing = (ARGV[7] == nil) puts thing.inspect: argv.rb
    # This is going to show you what the ARGV values do
    #
    # Just try some of these in console to see what happens:
    # $ ruby argv.rb 1
    # $ ruby argv.rb 1 2
    # $ ruby argv.rb hi hello
    # $ ruby argv.rb 1 hi message.txt
    
    variable = ARGV
    p variable
    
    puts ARGV[0]
    puts ARGV[1]
    puts ARGV[2]
    
    thing = (ARGV[7] == nil)
    
    puts thing.inspect
    
    
    

    external by zhengwong  392  0  3  0

    ARGC, ARGV, ARGN, ARGVn in CMake

    ARGC, ARGV, ARGN, ARGVn in CMake: function-argument.cmake
    cmake_minimum_required(VERSION 2.8)
    
    function(use_llvm TARGET)
    message("ARGC=\"${ARGC}\"")
    message("ARGN=\"${ARGN}\"")
    message("ARGV=\"${ARGV}\"")
    message("ARGV0=\"${ARGV0}\"")
    message("ARGV1=\"${ARGV1}\"")
    endfunction()
    
    add_custom_target(foo
    COMMAND ls)
    
    use_llvm(foo core bitwriter)
    
    # Results:
    # ARGC="3"
    # ARGN="core;bitwriter"
    # ARGV="foo;core;bitwriter"
    # ARGV0="foo"
    # ARGV1="core"
    
    

    external by David Szczesniak  24  0  1  0

    These can be named anything you want for the most part; using letters, digits and under-scores (can't start with digit). However, there are some common ones that Perl has created. These are STDIN, STDOUT, STDERR, DATA, ARGV, ARGVOUT.

    These can be named anything you want for the most part; using letters, digits and under-scores (can't start with digit). However, there are some common ones that Perl has created. These are STDIN, STDOUT, STDERR, DATA, ARGV, ARGVOUT.: filehandles.pl
    \!h # STDIN & STDOUT - the barebones
    # STDIN  - your program should blindy read from this (input).
    # STDOUT - and blindly write to this (output).
    $ ./your_program <dino >wilma # shell prompt command
    # ^ The program's input should be read from the file 'dino' amd the output should go to the file 'wilma'
    # The program will also work in a pipeline:
    $ cat fred barney | sort | ./your_program | grep something | lpr 
    # 
    
    

    external by rhyseda  114  0  2  0

    ARGV clear

    ARGV clear: argv_test.rb
    class MyTest
    
      attr_reader :cl_arguments
    
      def initialize
        @cl_arguments = ARGV.clone
      end
    
      def display
        puts "Displaying the ARGV array"
        puts ARGV
      end
    
      def argv_clear
        ARGV.clear
      end
    
      def display_cl_options
        puts "Displaying the command line arguments"
        puts cl_arguments
      end
    
    
    end
    
    
    testy = MyTest.new
    
    testy.display_cl_options
    
    testy.display
    
    testy.argv_clear
    
    testy.display
    
    testy.display_cl_options
    
    
    
    

    external by mojocorp  22  0  1  0

    Windows winmain argc argv console application

    Windows winmain argc argv console application: winmain.cpp
    #ifdef _WIN32
    #include <windows.h>
    #include <stdio.h>
    
    #pragma warning(disable: 4996)
    
    extern int main(int argc, char* argv[]);
    
    int WINAPI WinMain(HINSTANCE /*hInstance*/,
                       HINSTANCE /*hPrevInstance*/,
                       LPSTR /*lpCmdLine*/,
                       int /*nCmdShow*/)
    {
        // Redirect stdin, stdout, stderr to the console.
        if (AttachConsole(ATTACH_PARENT_PROCESS)) {
            freopen("CONIN$", "r", stdin);
            freopen("CONOUT$", "w", stdout);
            freopen("CONOUT$", "w", stderr);
        }
    
        return main(__argc, __argv);
    }
    #endif //_WIN32
    
    

    external by Jean Pierre Dudey  22  0  1  0

    Can i wrap argc and argv to an object in C++?

    Can i wrap argc and argv to an object in C++?: README.md
    # Can i wrap `argc` and `argv` to an object in C++?
    Lets say you're a purist *object oriented* programmer and you want wrap the `argc` and `argv` constant variables in a more situable
    container like `std::vector` and don't know how?
    
    Here is the pre-canned solution just for you (licensed under the [WTFPL][1]):
    ```c++
    // File: ArgumentsList.hpp
    typedef std::vector<std::string> ArgumentsList;
    
    void fill_arguments(ArgumentsList &args, int argc, const char **argv)
    {
        for (int i = 0; i < argc; i++)
            args[i] = std::string(argv[i]);
    }
    ```
    
    And use it like this:
    ```c++
    #include "ArgumentsList.hpp"
    
    void print_arguments(const ArgumentsList &arguments)
    {
        for (int i = 0; i < arguments.size(); i++)
            std::cout << "arguments[" << i << "]: " << arguments[i] << std::endl;
    }
    
    int main(int argc, const char **argv)
    {
        ArgumentsList arguments(argc);
    
        fill_arguments(arguments, argc, argv);
    
        print_arguments(arguments);
    
        return 0;
    }
    ```
    
    [1]: http://www.wtfpl.net/
    
    

    external by gerriet-hinrichs  22  0  1  0

    Small php function that parses the argv array from a string.

    Small php function that parses the argv array from a string.: cmdparser.php
    <?php
    
    function parse ($cmd)
    {
        $out = array();
        $escape = '';
        $buffer = '';
        $last = '';
        $i = 0;
        while (empty($char = mb_substr($cmd, $i++, 1)) === false)
        {
            switch ($char)
            {
                case '\\':
                    if ($last === '\\')
                    {
                        $buffer .= '\\';
                    }
                    break;
                case '\'':
                    if ($escape === '\'' && $last !== '\\')
                    {
                        $out[] = $buffer;
                        $buffer = '';
                        $escape = '';
                    }
                    elseif ($escape === '')
                    {
                        $escape = '\'';
                    }
                    else
                    {
                        $buffer .= $char;
                    }
                    break;
                case '"':
                    if ($escape === '"' && $last !== '\\')
                    {
                        $out[] = $buffer;
                        $buffer = '';
                        $escape = '';
                    }
                    elseif ($escape === '')
                    {
                        $escape = '"';
                    }
                    else
                    {
                        $buffer .= $char;
                    }
                    break;
                case ' ':
                    if ($escape === '' && $last !== '\\')
                    {
                        if ($buffer !== '')
                        {
                            $out[] = $buffer;
                            $buffer = '';
                        }
                    }
                    else
                    {
                        $buffer .= $char;
                    }
                    break;
                default:
                    if ($char !== '\\')
                    {
                        if ($last === '\\')
                        {
                            $buffer .= '\\';
                        }
                        $buffer .= $char;
                    }
                    break;
            }
            $last = $char;
        }
        if ($buffer !== '')
        {
            $out[] = $buffer;
        }
        return $out;
    }
    
    

    external by maxplomer  11  0  1  0

    need to use shift to get args from argv otherwise will mess up gets

    need to use shift to get args from argv otherwise will mess up gets: argv_test.rb
    def argv_test
      filename = ARGV.shift
      game_save = File.readlines(filename)
      p game_save
      x = gets.chomp
      p x
    end
    
    argv_test
    
    

    external by Github  708  0  3  0

    ARGC, ARGV, ARGV, ARGn in CMake

    ARGC, ARGV, ARGV, ARGn in CMake: function-argument.cmake
    cmake_minimum_required(VERSION 2.8)
    
    function(use_llvm TARGET)
    message("ARGC=\"${ARGC}\"")
    message("ARGN=\"${ARGN}\"")
    message("ARGV=\"${ARGV}\"")
    message("ARGV0=\"${ARGV0}\"")
    message("ARGV1=\"${ARGV1}\"")
    endfunction()
    
    add_custom_target(foo
    COMMAND ls)
    
    use_llvm(foo core bitwriter)
    
    # Results:
    # ARGC="3"
    # ARGN="core;bitwriter"
    # ARGV="foo;core;bitwriter"
    # ARGV0="foo"
    # ARGV1="core"
    
    
    • Public Snippets
    • Channels Snippets