0

I am trying to execute spectacle from a python script. v2.7. I am using spectacle to generate static HTML documentation for a yang model.

Spectacle creates a directory with the html doc and 2 subdirectories for css and javascripts.

When I execute from terminal it works fine. When I try the same command string using os.system or subprocess call, it errors out with code 32512 and 127 resp.

Below is the cmd string:

exe_spec = '/usr/local/bin/spectacle /Users/mwatt/swagpytest/Cisco-IOS-XR-ip-bfd-cfg.yang.json'
>>> os.system(exe_spec)
32512 
>>> subprocess.call(exe_spec, shell=True)
127

On executing from terminal the folders and files in swagpytest is as follows:

public
    |--- javascripts (2 files)
    |--- stylesheets (4 files)
    |--- index.html

Spectacle allows target directory to be specified in command line, default is public. I tried by putting in full path but to no avail.

exe_spec = '/usr/local/bin/spectacle -t /Users/mwatt/swagpytest/public/ /Users/mwatt/swagpytest/Cisco-IOS-XR-ip-bfd-cfg.yang.json'

Any similar experiences? Thanks.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
mpedro
  • 9
  • 3
  • 1
    FYI -- it's very much better practice to avoid `shell=True`. `subprocess.call(['/usr/local/bin/spectacle', '/Users/mwatt/swagpytest/Cisco-IOS-XR-ip-bfd-cfg.yang.json'])` would have avoided the need for a shell in the first place, potentially resulting in a more meaningful exit status or exception (since 127 is typically set by the shell itself when it can't find a command). – Charles Duffy Jun 23 '18 at 00:46
  • 1
    (BTW, to back up the "very much better practice" assertion -- see the big red warning section in https://docs.python.org/2/library/subprocess.html#frequently-used-arguments re: shell=True). – Charles Duffy Jun 23 '18 at 00:48
  • Thanks. I tried shell=False as well and got "OSError: [Errno 2] No such file or directory". Just do not know how else to specify path. – mpedro Jun 23 '18 at 00:51
  • That means it can't find `/usr/local/bin/spectacle` -- it's only the first argument that matters for that error, so you can stop worrying about whether the others are wrong. Are you sure `/usr/local/bin` is **really** where it's installed? – Charles Duffy Jun 23 '18 at 01:40
  • It's also worth looking at the context in which it's invoked -- if the script is run in a Docker container, for example, it's the container's `/usr/local/bin` that matters, not the host's. – Charles Duffy Jun 23 '18 at 01:42
  • Thanks. Its on mac. Just found that the /usr/local/bin/spectacle is a symlink to /usr/local/lib/node_modules/spectacle-docs/bin/spectacle.js . I guess I have to find a way to execute the .js – mpedro Jun 23 '18 at 04:01

0 Answers0