Passing multiple lines of code to wsadmin.sh?

Question:

I would like to pass a few lines of code to a WebSphere profile.

Here’s what I attempted:

# ./wsadmin.sh -lang jython -c 'print("Hello")
> print("World!")'

This printed out a response of:

WAS7209I: Connected to process"<my profile name>" on node <node name> using SOAP connector; The type of process is: UnManagedProcess
Hello

Note that it seems to just ignore the same line of code.

When I try the same thing in Python, it works fine:

# python -c 'print("Hello")
> print("World!")

Prints:

Hello
World!

I’m using WebSphere version 8.5 on CentOS 7.

Note: After getting Ram Vennam’s answer, I posted a related question with a different slant on Super User: https://superuser.com/q/939746/240375 – this is where I really ended up getting my answer.

Asked By: ArtOfWarfare

||

Answers:

You can use a semicolon:

./wsadmin.sh -lang jython -c 'print("Hello");print("World!")'

or, a script file can be given as input using –f option along with wsadmin.

$ wsadmin.sh –f your_script_file

Answered By: Ram Vennam

Edward’s Answer on SuperUser and Brett Kail’s comment on Ram Vennam’s Answer here both offered the same solution at roughly the same time, but neither of them posted it as an answer here when I asked them to, so I’m posting here so I have a correct answer to accept.

$ ./wsadmin.sh -lang jython -f <(echo 'print("Hello")
> print("World")')

Works perfectly. It allows you to put line returns in. It respects indentation, so you can have for loops and define functions and classes and everything else that requires indented lines.

An an added bonus, I’ll share how you can escape single quotes in your code:

'''

The first quote closes the preceding string. ' puts a single quote literal in. The last quote starts the next string. Bash automatically joins the three together to form one contiguous string with a single quote in the middle of it. So if I wanted to use single quotes instead of double quotes above, it would look like this:

$ ./wsadmin.sh -lang jython -f <(echo 'print('''Hello''')
> print('''World''')')
Answered By: ArtOfWarfare
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.