logo
down
shadow

How to calling a function with arguments in one .rb script to another .rb script


How to calling a function with arguments in one .rb script to another .rb script

By : user2951914
Date : November 18 2020, 03:49 PM
hop of those help? I am new to Ruby language. i want to work with ruby language, i have installed ruby 2.1.5 and i am trying to calling one .rb script to another .rb script with arguements and can you please suggest me how to do this. i have written following code , You need to change code to this -
a.rb:
code :
require_relative 'b'

def sample
  $a = 1
  $b = 3
  $c = 4
  $str = "hello"
  eval "#{$str}(#{$a},#{$b},#{$c})"
end

sample
def hello(a, b, c)
  d = a + b +c
  print "d value is : " + d.to_s
end
$ ruby a.rb
#=> d value is : 8


Share : facebook icon twitter icon
Calling one Bash script from another Script passing it arguments with quotes and spaces

Calling one Bash script from another Script passing it arguments with quotes and spaces


By : 陳韋馨
Date : March 29 2020, 07:55 AM
hope this fix your issue I made two test bash scripts on Linux to make the problem clear. TestScript1 looks like: , Quote your args in Testscript 1:
code :
echo "TestScript1 Arguments:"
echo "$1"
echo "$2"
echo "$#"
./testscript2 "$1" "$2"
Bash Script: how to pass arguments to a function of a running script from another one?

Bash Script: how to pass arguments to a function of a running script from another one?


By : TheGhost
Date : March 29 2020, 07:55 AM
I wish this helpful for you For this kind of functionality, every language relies on interprocess messaging. In bash it always is a bit hackish because it is not "cooked&ready".
I tried to change as little as possible to your code (did fix some syntax though).
code :
#!/bin/bash
mkfifo "/tmp/$$" ; exec 3<>"/tmp/$$"  
doSomething() { echo "$1" >&3 ; pkill -SIGUSR1 "runningScript.sh" ;}


VALUE_OF_EXIT_CODE=256

/home/dev/runningScript.sh $arg1 $arg2 &


# some code

doSomething "$VALUE_OF_EXIT_CODE" 
#!/bin/bash

trap "read EXIT_CODE <&3" SIGUSER1

while something
do
if [ $EXIT_CODE = 0 ]; then
     echo "normal exit => OK"  
     exit 0
fi
# If the exit code is not 0, then there was a error.
if [ $EXIT_CODE -gt 0 ]; then
    echo "Error => $EXIT_CODE"
    exit $EXIT_CODE 
fi
done
Call a main function from a second Python script using arguments determined in the second script

Call a main function from a second Python script using arguments determined in the second script


By : mark
Date : March 29 2020, 07:55 AM
Hope this helps I have a Python function that takes 2 filenames and does some stuff with them. I want to write a wrapper script that will determine the filenames and call the main function of the original script with those arguments. I am very inexperienced with Python, does anybody know the simplest way to do this? , cat test.py
code :
def main(a,b):
    return a+b
from test import main

print main(5,3)
How to get the complete calling command of a BASH script from inside the script (not just the arguments)

How to get the complete calling command of a BASH script from inside the script (not just the arguments)


By : Darshan Pania
Date : March 29 2020, 07:55 AM
With these it helps I have a BASH script that has a long set of arguments and two ways of calling it: , You can try the following:
code :
myInvocation="$(printf %q "$BASH_SOURCE")$((($#)) && printf ' %q' "$@")"
 $ printf %q 'a |b'
 a\ \|b
my_script "$BASH_COMMAND" --option1 value --option2
# The *first* argument is what "$BASH_COMMAND" expanded to,
# i.e., the entire (alias-expanded) command line.
myInvocation=$1    # Save the command line in a variable...
shift              # ... and remove it from "$@".

# Now process "$@", as you normally would.
# The *first* argument is what "$BASH_COMMAND" expanded to,
# i.e., the entire (alias-expanded) command line.
# Here we also re-transform the alias-expanded command line to
# its original aliased form, by replacing everything up to and including
# "$BASH_COMMMAND" with the alias name.
myInvocation=$(sed 's/^.* "\$BASH_COMMAND"/my_script/' <<<"$1")
shift              # Remove the first argument from "$@".

# Now process "$@", as you normally would.
How to pass arguments to python script similar to MATLAB function script?

How to pass arguments to python script similar to MATLAB function script?


By : Damien Carrier
Date : March 29 2020, 07:55 AM
may help you . You can use the results directly just like you do in MATLAB. The argument parsing stuff is for calling python scripts from the system command prompt or shell, not from the Python shell. So have a script file like myscript.py:
code :
def metrics(minval, maxval):
    """UNTITLED Summary of this function goes here

    Detailed explanation goes here.
    """
    x = [1, 2, 3, 4, 5, 5]

    if minval:
        print(min(x))
    else:
        print('something')

    if maxval:
        print(max(x))
    else:
        print('else')
>>> from myscript import metrics
>>> metrics(1, 0)
def metrics(minval=False, maxval=False):
    """UNTITLED Summary of this function goes here

    Detailed explanation goes here.
    """
    x = [1, 2, 3, 4, 5, 5]

    if minval:
        print(min(x))
    else:
        print('something')

    if maxval:
        print(max(x))
    else:
        print('else')
>>> from myscript import metrics
>>> matrics(True)
>>> metrics(maxval=True)
    if maxval:
        print(max(x))
    else:
        print('else')
    print(max(x) if maxval else 'else')
Related Posts Related Posts :
  • How to implement custom mutating methods in Ruby?
  • Precedence operators in Ruby from Haskell?
  • How to install command line tools on OSX Mavericks
  • When making network requests, when should I use Threads vs Processes?
  • how to call method in one application from another application in ruby on rails
  • LoadError on line ["51"] when trying compass watch command
  • Why does `Dir[directory_path].empty?` return `false` all the time?
  • ruby conjunction and union operators
  • Ruby - watch for file with extension being updated
  • How do I have Ruby YAML dump a Hash subclass as a simple Hash?
  • How do I get ruby-prof to ignore Ruby core / standard library / gem methods?
  • How do I give my instance variable a getter?
  • syntax error, unexpected '=', expecting keyword_end
  • Symbol literal or a method
  • Singleton logger usage in ruby
  • Difficult code packaging design
  • Passing absent parameters
  • Is there a more efficient way of ensuring my database gets closed?
  • Take in escaped input in Ruby command line app
  • String with comma-separated values and newlines: split values and create arrays for each newline
  • Instance variables on Ruby main class
  • How do I cache user specific objects
  • How to specify the location of the chromedriver binary
  • How to setup "application/ld+json" schema.org meta data in rails 4 app
  • How to use String split[]
  • Capture Ruby Logger output for testing
  • Regex group match if present
  • Unusual use of module namespacing
  • Why doesn't this loop stop?
  • How do I run Rails/Rake from another directory?
  • Ruby Tempfile doesn't Create File on Disk
  • Consecutive letter frequency
  • Calling second-level function from the second level in Ruby
  • How do I use a Chef Resource in a Library
  • Ruby Method Name Interpolation
  • Weird behavior of #upcase! in Ruby
  • Ruby array access position in array
  • Ruby NameError: Undefined local variable
  • Using Nokogiri to validate XML: finding the line-nr of validation errors?
  • Get and clear cookie using rest-client
  • invalid argument creating a ruby dev env with docker & fig
  • How can I better test equality for decorated objects?
  • Replace text in brackets gsub
  • Ruby's Array Combination Method
  • Don't have access to Heroku app
  • Take any hash keys and flatten into mixed array
  • Ruby On Rails Relationship Between Model, View, And Controller
  • Quitting method chain execution early
  • Data scrapping with Nokokiri and Pismo
  • Date format ends before converting entire input string
  • Rails 4: display values for lookups
  • Search for uppercased substring
  • Check params presence in Grape
  • How to create a method that checks if string1 can be rearranged to equal string2?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org