[{"user_id": 34979, "stars": [], "topic_id": 38631, "date_created": 1307548863.5811529, "message": "I am trying to invoke the WHERE utility on Windows. I have the following:", "group_id": 292, "id": 1338765}, {"user_id": 34979, "stars": [], "topic_id": 38631, "date_created": 1307548923.3912711, "message": "l = 'json_simple-1.1.jar'\t\t\t\r\ncwd = os.getcwd() + '\\lib'\r\n\t\t\to = subprocess.check_output(['where', '/Q \"{1}:{0}\"'.format(l, cwd)])\r\n\t\t\tprint o", "group_id": 292, "id": 1338780}, {"user_id": 34979, "stars": [], "topic_id": 38631, "date_created": 1307548866.9099669, "message": "I am trying to invoke the WHERE utility on Windows. I have the following:", "group_id": 292, "id": 1338767}, {"user_id": 34979, "stars": [], "topic_id": 38631, "date_created": 1307548993.1076119, "message": "My question is - does it matter if the path contains double slashes when its being passed to where. Can I escape these if so? Thanks.", "group_id": 292, "id": 1338792}, {"user_id": 34979, "stars": [], "topic_id": 38631, "date_created": 1307548860.278456, "message": "I am trying to invoke the WHERE utility on Windows. I have the following:", "group_id": 292, "id": 1338762}, {"user_id": 34979, "stars": [], "topic_id": 38631, "date_created": 1307549060.947319, "message": "Sorry for the double post on first part of question, my internet is so slow.", "group_id": 292, "id": 1338800}, {"user_id": 10377, "stars": [{"date_created": 1307650580.0221419, "user_id": 1736}], "topic_id": 38631, "date_created": 1307552960.8900011, "message": "why not use os.path.join?", "group_id": 292, "id": 1339328}, {"user_id": 8649, "stars": [{"date_created": 1307650580.5218401, "user_id": 1736}], "topic_id": 38631, "date_created": 1307560767.7962461, "message": "Agreed with tiarno: use os.path.join(os.getcwd(), \"lib\")", "group_id": 292, "id": 1340949}, {"user_id": 8649, "stars": [{"date_created": 1307967318.1122711, "user_id": 5778}], "topic_id": 38631, "date_created": 1307560903.025599, "message": "You should be VERY careful about embedding raw backslashes in strings. You should always prefix the string with 'r', as in r\"\\lib\". This makes sure that the backslash is not interpreted as an escape. (In this case, since \\l is not a valid escape sequence, the backslash passes through fine, but if that path ever changes to something else, you'll have a very subtle bug. Last year I helped a guy debug exactly this problem in his code - it was working for some directories but not others, and it came down to unescaped backslashes.)", "group_id": 292, "id": 1340975}, {"user_id": 10377, "stars": [{"date_created": 1307766388.009357, "user_id": 34414}], "topic_id": 38631, "date_created": 1307561104.436682, "message": "This isn't what you were asking, but another trick I like for using subprocess is to put together the command to execute in a string and call shlex.split(command_string) as the first arg. That way shlex does the work of figuring out how to parse the command into parts.", "group_id": 292, "id": 1341039}, {"user_id": 31883, "stars": [], "topic_id": 38631, "date_created": 1307599096.0882411, "message": "you can use '/' to separate parts in paths on windows", "group_id": 292, "id": 1346720}, {"user_id": 34979, "stars": [{"date_created": 1308313550.9393511, "user_id": 36412}, {"date_created": 1309200869.5431421, "user_id": 36069}], "topic_id": 38631, "date_created": 1307607250.064863, "message": "Thanks, the solution I used was to just use: o = subprocess.check_output(['where', 'lib:{0}'.format(l)) as I just needed to search for l in the lib subdir. But your suggestions on how to resolve the absolute path are appreciated. Thanks all. :)", "group_id": 292, "id": 1347290}, {"user_id": 20326, "stars": [], "topic_id": 38631, "date_created": 1308084950.2619259, "message": "@tiarno I don't like doing that at all and would never do it when I was doing string interpolation on the command. Doing so would be error prone because you would have to care about, for example, whether your interpolants have spaces in them. This is the power of making the list directly, and if you try it's really not hard to get used to thinking this way. (We're already used to it on the receiving end.)", "group_id": 292, "id": 1394067}, {"user_id": 10377, "stars": [], "topic_id": 38631, "date_created": 1308314318.4676809, "message": "@mikegraham, are you talking about using shlex with subprocess? I thought it was a best practice from the docs:http://docs.python.org/library/subprocess.html and http://stackoverflow.com/questions/4091242/subprocess-call-requiring-all-parameters-to-be-separated-by-commas It seems like that's what shlex is meant for. Maybe I misunderstand you.", "group_id": 292, "id": 1418502}, {"user_id": 36412, "stars": [], "topic_id": 38631, "date_created": 1308313537.9125979, "message": "Hihi", "group_id": 292, "id": 1418434}, {"user_id": 31883, "stars": [], "topic_id": 38631, "date_created": 1308551750.212656, "message": "@tiarno: if you *already have* a command line (e.g. from a user-edited config file), then shlex is appropriate. but if you are building the invocation entirely yourself (which it sounds like you are), then there is no reason to use shlex: instead, build the argument list yourself, and then pass it to subprocess.", "group_id": 292, "id": 1436319}, {"user_id": 20326, "stars": [], "topic_id": 38631, "date_created": 1308599641.4370091, "message": "@tiarno That is what I am talking about, and I really don't think shlex.split proves useful for many practical cases. Real cases very frequently look like `def f(x, y): Popen([\"/bin/something\", \"-d\", x, \"--name=%s\" % y])`. I could attempt to write this as `def f(x, y): Popen(shlex.split(\"/bin/something -d %s --name=%s\"))`, but I would run into trouble when I tried `f(\"Jan 20 1991\", \"Mike Graham\")`.\n\nIf you have a static command you might find it easier to write it that way, but personally I prefer just to create the list almost always", "group_id": 292, "id": 1441851}, {"user_id": 10377, "stars": [], "topic_id": 38631, "date_created": 1308671354.7649601, "message": "okay, I see what you're talking about. I just don't want to think about how to chop up the command line string myself. I get your point but it seems to me like a personal preference.", "group_id": 292, "id": 1449549}, {"user_id": 38809, "stars": [], "topic_id": 38631, "date_created": 1311789321.9653461, "message": "I have to `ls`*", "group_id": 292, "id": 1733067}, {"user_id": 38809, "stars": [], "topic_id": 38631, "date_created": 1311789291.301239, "message": "Guys, is there a way to improve either a combination of os.popen()+read() or subprocess.check_output()? I have `ls` a number of folders and read the outputs, and using either of the above - results in a running time bottleneck...", "group_id": 292, "id": 1733066}, {"user_id": 20326, "stars": [{"date_created": 1311794435.4787409, "user_id": 1822}], "topic_id": 38631, "date_created": 1311793368.234339, "message": "@melnikovkolya, Why are you using ls rather than os.listdir?", "group_id": 292, "id": 1733481}, {"user_id": 22625, "stars": [], "topic_id": 38631, "date_created": 1311840453.9524889, "message": "or glob.glob() - or os.walk() :)", "group_id": 292, "id": 1737478}]