h2 set path/environment variables
-
On 14/10/2015 at 07:42, xxxxxxxx wrote:
How can I set within python %path% or environment variables that are recognized by the windows pc command line (cmd).
I want to start an external application located in "C:\Program Files (x86).....", but starting this application with os.system() is not recognized because of the first space.
I tried using a bat files, but starting a bat with a path including spaces, also fails.If I can define a path or environment variable, it should be ok.
-Pim
PC Windows 8.1
-
On 14/10/2015 at 10:07, xxxxxxxx wrote:
something like?
import os pr32 = os.environ['ProgramFiles(x86)'] # get enviro var print pr32 """ os.environ['MYVAR'] = 'path' # set enviro var """
subprocess and etc.
-
On 14/10/2015 at 23:54, xxxxxxxx wrote:
But that is a local setting.
When I start up cmd, the MYVAR environment variable is not known.So, how to define a global environment variable?
-Pim
-
On 15/10/2015 at 01:28, xxxxxxxx wrote:
Hi,
while of course you can go down the environment variable road, you could also simply use the os.system() road with a properly formatted path.
a) I'd recommend not to use backslash (\) as directory separator. In Python you can use the normal slash as well under Windows. This has the advantage, that the slash does not need to be escaped. So instead of 'C:\\dir\\walter.exe' you can simply use 'C:/dir/walter.exe'.
b) In order to use spaces in filepaths, Windows expects the path to be enclosed in quotation marks. Then your path looks like so (note that the quotation marks have to be escaped using the backslash) : '"C:/dir with space/walter.exe"'
So in your case: os.system('"C:/Program Files (x86)/..."')
-
On 15/10/2015 at 01:35, xxxxxxxx wrote:
Yes, and putting everything between quotes solved the issue.
So instead of cd c:\program files
cd "c:\program files"Thanks, pim
-
On 15/10/2015 at 07:22, xxxxxxxx wrote:
strange
i made test with such code all is okimport c4d import os, sys, subprocess def main() : pr32 = os.environ['ProgramFiles(x86)'] # get enviro var b = pr32 + '/opera/opera.exe' subprocess.Popen(b) if __name__=='__main__': main()
>> b if printed is C:\Program Files (x86)/opera/opera.exe
-
On 15/10/2015 at 07:28, xxxxxxxx wrote:
As Ilya said, you should definitely do it using the subprocess module.
-
On 15/10/2015 at 08:29, xxxxxxxx wrote:
WOW this is so helpful guys , nice and thanks for sharing guys. But any tread on Reg..Key that can help? or its the same.
-
On 15/10/2015 at 09:01, xxxxxxxx wrote:
Originally posted by xxxxxxxx
As Ilya said, you should definitely do it using the subprocess module.
Ok, I used os.system.
Shall test it with the examples given.Thanks, Pim
-
On 16/10/2015 at 00:54, xxxxxxxx wrote:
On the Mac I get an error OSError: [Errno 2] No such file or directory.
It complains about .../python.2.6/subprocess.py" line 1126 in_execute _child.I did not yet tested it on a pc.
On the Mac I am using R16.047.
-Pim
-
On 16/10/2015 at 01:20, xxxxxxxx wrote:
Originally posted by xxxxxxxx
On the Mac I get an error OSError: [Errno 2] No such file or directory.
It complains about .../python.2.6/subprocess.py" line 1126 in_execute _child.I did not yet tested it on a pc.
On the Mac I am using R16.047.
-Pim
hi
I test at windows os, example for opera(web browser, if installed).
I have question, have you rules what enviro to use? i mean this:import os, platform, sys if platform.system().lower().startswith('win') : # winos pass elif platform.system().lower().startswith('dar') : # macos pass
under pass - your functions with vars
-
On 16/10/2015 at 01:45, xxxxxxxx wrote:
Yes, I use
if c4d.GeGetCurrentOS() == c4d.GE_WIN: windows ... else: mac ...
-
On 16/10/2015 at 01:59, xxxxxxxx wrote:
argh, sorry, i'm with code from my studying of scons(exescons)
can post what targets of mac os you want, maybe mac users will help you
-
On 16/10/2015 at 02:09, xxxxxxxx wrote:
This is the command I want to give on the Mac:
/Applications/cloud_ui/ccl --help
I tested subprocess.Popen on the pc and it works ok.
Just like os.system.What is the difference between os.system and subprocess.Popen?
-Pim
-
On 16/10/2015 at 02:15, xxxxxxxx wrote:
mmm, you need also shell commands or args for app
take look - https://docs.python.org/2/library/subprocess.html#popen-constructor -
On 16/10/2015 at 07:00, xxxxxxxx wrote:
Any input on my subprocess.Popen issue?
On the Mac I get an error OSError: [Errno 2] No such file or directory.
It complains about .../python.2.6/subprocess.py" line 1126 in_execute _child.On a pc, I got the same error message.
-
On 16/10/2015 at 08:03, xxxxxxxx wrote:
I got it now working.
Here an example on the pc, generating a tasklist and checking if a process is running.ps= subprocess.Popen(r'tasklist.exe', shell=True, stdout=subprocess.PIPE) output = ps.stdout.read() ps.stdout.close() ps.wait() if ("cloud_ui" in output) : print "found" else: print "not found"