简体   繁体   中英

Is there any way to put a variable inside telnet command in python?

is there any way to put the variable posorprom inside the telnet command in python? Here is a peace of my code:

posorprom = prom

tn.write(b"ls /mnt/flash/prom | wc -l\n")

i want to put the variable posorprom inside the command, so i already tried this:

tn.write(b"ls /mnt/flash/" + posorprom + " | wc -l\n")

but it doesnt work. please help me.

Well you seem to concatenate different kinds of strings, since you use raw byte strings for one string, then all the strings must be that:

posorprom = b"prom"
tn.write(b"ls /mnt/flash/" + posorprom + b" | wc -l\n")

posorprom = prom does not set the variable posoprom to "prom", but to the value of the variable prom.

Try posorprom = "prom" instead.

posorprom = "prom" tn.write("ls /mnt/flash/" + posorprom + " | wc -l\\n")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM