string with new line

2,370 views
Skip to first unread message

Philip

unread,
Jun 1, 2016, 6:48:16 PM6/1/16
to robotframework-users
I can not figure what is wrong with this and I tried all things but I still can not figure out.

Open SHH connection  |  ${host}
Login   ${name} | ${pass}
Write   | ls abcd*.iso
${fileIso}= | read until regexp | #

Log  | ${fileIso} 

      # ${fileIso} = abcd1.-1.5.1.SNAPSHOT.4165.iso            

Log  | mount -o loop ${fileIso} ${directory}                     #where ${directory} is an argument

The output will be
 # moutn -o loop abcd1.-1.1.1.SNAPSHOT.29888.iso         #abcd-directory jumps to a next line
 # abcd-directory

So I wrote a python code to replace \n or \r with " " for the variable ${fileIso} and
I also removed the remove a while space before and after of the variable ${fileIso"

Log still shows a new line for the ${directory} variable

Log  | moutn -o loop ${fileIso} ${directory}                     #where ${directory} is an argument

The output still show
 # mout -o loop abcd1.-1.1.1.SNAPSHOT.29888.iso
 # abcd-directory

Tatu Aalto

unread,
Jun 2, 2016, 1:29:10 AM6/2/16
to Phillip Do, robotframework-users

Ugh

With out seeing the Python code and snippets what the variables actually contain it's impossible to say anything concrete. But as a wild guess I would assume that your Python code is not doing what you assume.

As a side note you don't need to build a new keyword to remove a whitespace from a string. There is a Strip String[1] keyword in the String library, which does the trick.

-Tatu

[1] http://robotframework.org/robotframework/latest/libraries/String.html#Strip%20String

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Philip

unread,
Jun 2, 2016, 2:10:16 AM6/2/16
to robotframework-users, pdo...@gmail.com
The python code I wrote:

def strip_charreturn_newline(string1):
    output = string1.replace('\n', "")
    output = string1.replace('\r', "")
    return output
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

Heiko Thiery

unread,
Jun 2, 2016, 2:32:14 AM6/2/16
to pdo...@gmail.com, robotframework-users
i think you should focus on the location where you get the ${directory} values... there should be the problem? what way do you get this value? but as tatu wrote, you can use the strip string keyword to remove leading and/or trailing whitespaces.

To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.

Philip

unread,
Jun 2, 2016, 2:37:58 AM6/2/16
to robotframework-users, pdo...@gmail.com
${directory} is an argument and the value is input value. for example, "abcinstall"
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

Philip

unread,
Jun 2, 2016, 3:00:00 AM6/2/16
to robotframework-users, pdo...@gmail.com
I noted above that the ${fileIso} gets a value from the sshlibrary.write  | ls abcd*.iso and the ${directory} is a value which is passed to an argument/

Heiko Thiery

unread,
Jun 2, 2016, 3:40:45 AM6/2/16
to pdo...@gmail.com, robotframework-users
ok .. 

the problem seems to come from here:

Write   | ls abcd*.iso
${fileIso}= | read until regexp | #

there you read till the prompt of your shell. but the prompt appears after a newline.

try to change your code to use the execute command from ssh library. then the correct prompt will be stripped.

---
Open Connection  
${host}   prompt=#
${fileIso}  ${rc}=  Execute Command  ls abcd*.iso  return_rc=True
Should Be Equal  ${rc}  0  msg=Return code is ${rc} but should be 0.
Log  ${fileIso} 
---

give it a try ...


To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.

To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.

Philip

unread,
Jun 2, 2016, 4:17:49 PM6/2/16
to robotframework-users, pdo...@gmail.com
I manually count this string (the filename) and it is about 35 characters.
But I use the get length function of string and is is about 56 characters.

I use this python code to trim spaces, new line, character return and the get length function still 56 characters.

 def strip_charreturn_newline(string1):
    output = string1.strip(' \t\n\r')
    output = string1.rstrip(' \t\n\r')
    return output


you know why ?
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

Philip

unread,
Jun 2, 2016, 4:21:14 PM6/2/16
to robotframework-users, pdo...@gmail.com
Also I tested the split function to split this string with space into a list
it has the same issue.

Philip

unread,
Jun 2, 2016, 4:47:48 PM6/2/16
to robotframework-users, pdo...@gmail.com
Robot Framework: O.S WIndows
ls -l abce*.iso        : Centos 7


On Thursday, June 2, 2016 at 12:40:45 AM UTC-7, Heiko Thiery wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

Philip

unread,
Jun 2, 2016, 7:01:59 PM6/2/16
to robotframework-users, pdo...@gmail.com
sorry for the trouble.
In fact, I use the start command as you instruct instead of the write command and it works.

The issue as you pointed to.

thanks


On Thursday, June 2, 2016 at 12:40:45 AM UTC-7, Heiko Thiery wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages