0

I am developing a program which needs to use os.system because of the old Python limitations. Currently I'm stuck in one small spot.

os.system("C:\\FIOCheck\\xutil.exe  -i get phy" +HBEA + ">C:\\FIOCheck\\HBEAResult.txt")

This is the piece of code I am trying to work through. It will access an external program, which has some parameters. HBEA is the variable I am trying to pass (which is received earlier in the program). The program then takes whatever the .exe created and pipes it to an external file. At this point, the variable HBEA is not being passed to the command line, so the .exe never runs, which causes the .txt to be blank. Since the file is blank, I cannot grab data from it and therefore cannot complete the program.

Any ideas?

EDIT: So I attempted the following code per some suggestions:

cmd = "C:\\FIOCheck\\xutil.exe  -i get phy " +HBEA + ">C:\\FIOCheck\\HBEAResult.txt"
print cmd
os.system(cmd)

The following output was generated:

50012BE00004BDFF  #HBEA variable
C:\FIOCheck\xutil.exe  -i get phy 50012BE00004BDFF>C:\FIOCheck\HBEAResult.txt #the cmd  var

However this still isn't passing the value through. Is the HBEA variable too long?

SOLVED

This program worked with some editing from the best answer. The commands were passing correctly, however the way I formatted it was not correct. The new formatting looks like:

cmd = "C:\\FIOCheck\\xutil.exe -i " + HBEA + " get ver" + ">C:\\FIOCheck\\HBEAResult.txt"
os.system(cmd)

Thanks for the help!

Matt
  • 11
  • 1
  • 1
  • 4
  • 1
    Do you want to concatenate `'phy'` with the contents of `HBEA` ***without*** any space between them? When I set a value for `HBEA` it gets concatenated with your string, so it's not clear where you loose the value for that variable. Can you print it out immediately before you build this command? – Levon Jul 17 '12 at 15:11
  • I want to be able to pass HBEA through to the command line successfully. Currently the command runs perfectly, but the HBEA variable is missing. – Matt Jul 17 '12 at 15:12
  • I would print the value of `HBEA` first separeately, then I would build the command string (`cmd`) separately and print it to verify, and then call `os.system(cmd)` – Levon Jul 17 '12 at 15:13
  • Hi Levon, I tried that and I came up with the following: 50012BE00004BDFF C:\FIOCheck\xutil.exe -i get phy 50012BE00004BDFF >C:\FIOCheck\HBEAResult.txt Which is correct, however the number is still not being passed to the command line. It is still missing. – Matt Jul 17 '12 at 15:15
  • the way you have your code right now, you'll get `phy50012BE00004BDFF` .. not `phy 50012BE00004BDFF` so maybe you've changed something. Also, just go ahead an append a `'\n'` to your string. It *shouldn't* make a difference, but go ahead and try anyway. – Levon Jul 17 '12 at 15:21
  • The HBEA variable is definitely *not* too long. Is the command line parameter perhaps meant to passed on as a string, ie surrounded in double quotes? – Levon Jul 17 '12 at 15:22
  • If I do that, won't HBEA just be passed on as a string HBEA instead of a number? – Matt Jul 17 '12 at 15:27
  • Yes, some programs may expect their command line to come as strings .. I am not familiar with the program you are running. I'd also put a few more blanks around to the ` > C:\...` for readability. I think I'm out of ideas for remote trouble-shooting this, hopefully someone else has a solution. – Levon Jul 17 '12 at 15:30
  • somewhat more convenient snippet to replace **os.system** that I use a snippet as in here http://stackoverflow.com/a/18663914/544463 – Yauhen Yakimovich Sep 06 '13 at 18:04

1 Answers1

2
os.system("C:\\FIOCheck\\xutil.exe  -i get phy" +HBEA + ">C:\\FIOCheck\\HBEAResult.txt")

should that be

os.system("C:\\FIOCheck\\xutil.exe  -i get phy " +HBEA + ">C:\\FIOCheck\\HBEAResult.txt")

and you can always build the string first

cmd = "C:\\FIOCheck\\xutil.exe  -i get phy " +HBEA + ">C:\\FIOCheck\\HBEAResult.txt"
print cmd
os.system(cmd)
nate_weldon
  • 2,289
  • 1
  • 26
  • 32
  • This pretty much summarizes both of my comments above. – Levon Jul 17 '12 at 15:14
  • seems to be the first 2 things that i run into when i use the os command – nate_weldon Jul 17 '12 at 15:17
  • So I've been rattling around with this, and tried this step. Everything seems to work well in output however, I am still not passing the HBEA variable through for some reason. Sample output: 50012BE00004BDFF C:\FIOCheck\xutil.exe -i get phy 50012BE00004BDFF >C:\FIOCheck\HBEAResult.txt – Matt Jul 17 '12 at 15:17
  • Nate - it's being pulled from another file that creates it as 50012BE:00004BDFF. I simply extract the : and then pass this value off. – Matt Jul 17 '12 at 15:22