I'm trying to find out if I can execute a file via Maya or not. To be accurate: I wan't to know if CVS is accessible in Maya. It has to be set in the systems environment variables.
If I try to execute cvs.exe via system("cvs.exe") and its not set in environment variables of course there is an error in your operating systems language (eg here: "Der Befehl "cvs.exe" ist entweder falsch geschrieben oder konnte nicht gefunden werden.") But can I query if its available without producing that error?
unfortunately 'filetest' only works with full path.
Maybe its better to let the user set the path to CVS and save it with an optionVar ...
Well ist out of hands of maya and has more to do how your os is set up. But you can catch the error and use that as the clue. I mean the error is the sytems way of saying not available.
So you could use something like this on windows.
{ $prog="cvs.exe"; $output= system($prog); $error="'"+$prog+"' is not recognized as an internal or external command,rnoperable program or batch file.rn"; if ($output==$error){ print ("error " +$prog+" not found on this systemnproceeding to search for it on drive c:n"); $find=system("dir c: /s /b | find ""+$prog+"""); if ($find=="") print "does not exsit"; else print "found! now do soemthing about it such as set it into path, with the set command!"} else print ("output: "+$output); }
your error is probably
"Der Befehl "cvs.exe" ist entweder falsch geschrieben oderrnkonnte nicht gefunden werden.rn"
but you can allways use encodeString to get what it is.
PS. note configuring a sytem wich talks your native language in the shell is not amongst the smartest things in the world (and usualy not more user firendly and not more workable either), as it limits your options in your case slightly, the most horrible thing is localized versions of visual basic, also some external progs might stop working properly... UCK worst of all you cant share them across sytems. Since if even one of the sytems is not in your native tongue youve had it, the englis version offcourse works on them all.
PPS. a interesting fact is that why would germans need pointed out thet the quoted is a command? when english users dont... Oh well
puuhhh.. Thanks Joojaa for your detailed explanation!
No, unfortunately checking the systems output is not an option. We have no posibility to change the systems language in the whole company. And there might come more machines with german windows. Furthermore that script might run on machines with any language!!
I thought there might be something like 'filetest' only with an option to check without path.
I think the best way is simply to let the user point where that executable is located and then save it like I said in an optionVar.
PS: It works very fine. I think every developer considers that there might be other system languages. At least he should.
PS: It works very fine. I think every developer considers that there might be other system languages. At least he should.
No actualy every system should be able to reproduce the error in whatever language the developper wishes! Or actualy it would be sufficent if there was jsut one forced language that it resoponded in consitently, and then the optional install language.
And as a matter of factly you can temporarily switch tehe language back to english and then back to whatever it was before. so the error reproted will be consitent.
Theres a lot of problems with localization such as your third party utilities still speaking english. And note not all language areas have localized the command line responses. even toughe every otehr part of the sytem is. I think this si the sane solution. tough a vay to easily switch locales for the shell would be the BEST solution.
And no theres no mechanism for this becasue the returned sentence IS the mechanism. but yes you can dierctly use the search its just that ist a bit of a slow operation! so its better not to do so!
Alternate B is offcourse to know what cvs. exe returns and start searching if it does not return something cvs exe susualy does.
alternative C make a database of errors andcheck against that.
Alternative B was one thing I was thinking about too. But what, if other poeple use other versions of CVS? I can't go sure se same way as I can't with the system error.
Yea I'm your opinion : think localized commandline output is nonsense [hehe bull-excrement was censored
Hmm i was thinking about this and came with this solution instead!
proc int isFileInPath(string $file){ //widows specific code. string $path[]; tokenize(system("echo %path%"),";",$path); for ($dir in $path) if (file -q -ex ($dir+"/"+$file)==1) return 1; return 0; }
returns either 1 or 0 now it wont work on a linux or OSX offcourse but there you can chek against os and have code for that too!
just remeber that the sytemcommand
dir /s /b filetosearchfor
run in the disk root effectively searches for every file in the disk named like you specify. Its still a heawy operation so you could as user to either point for the file or let you atomagicaly search for it.
Paired with a for loop its a wery good way to batch render a entire project at once! Validate yoru entire sites html, parse each xml file on the disk with xslt, bakup all ma and mb files... and so on.
yes is just a alias for typing the command verbosely. (s are shorthand while the later method is the real deal as i se it)
So $result=ls -sl -dag -shapes ise equal to saying $result=ls("-sl","-dag","-shapes");, now the point with later is that you can put many retrieves in one line whereas only allows one level of them.