Question

I'm dealing 2 scripts in python. the first one needs to send a value or an argument to the second script. Now the problem is whenever I send the value to the 2nd script, the 2nd script couldn't get all the arguments that I sent. the value that Im sending is a URL and it contains an ampersand. I noticed that it kept on cutting the value to the first appearance of &.

lets sat for example, I need to pass this :

http://www.google.com/jfljflfjej&12345

the 2nd script will receive only this :

http://www.google.com/jfljflfjej

what do I need to do to be able to catch the correct value? And what other characters that have the same issue as this?

Was it helpful?

Solution

You need to put quotes around the whole value, including the ampersand, as it is a special shell character. Alternatively, you can escape just the ampersand by putting a backslash in front of it:

http://www.google.com/jfljflfjej\&12345

The ampersand signals to the shell you want to put the command up to that point in background mode.

Any of the following characters are special in a shell:

 \ ' " ` < > | ; <Space> <Tab> <Newline> ( ) [ ] ? # $ ^ & * =

These need to be escaped in the same way; use a backslash or put quotes around the value.

OTHER TIPS

Maybe it's a bit late to answer you but I had the same problem and I found a simple solution to that.

You can use the function replace() to replace every ampersand with their code in HTML '%26' like this.

url = http://www.google.com/jfljflfjej&12345
print url.replace('&', '%26')

And the result:

http://www.google.com/jfljflfjej%2612345

It's a problem of coding.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top