Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Kaeptm Blaubaer Newsgroups: de.comp.lang.python Subject: Re: [Python-de] probleme mit python 3 popen Date: Sun, 23 Sep 2018 18:13:48 +0200 Lines: 53 Message-ID: References: <33920c93-417b-ef60-4f54-cdfb878ed21c@redcor.ch> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de I81GK3vr8GdjnEUu3mh/hQzL7DptwAD2LZxqtELp3AnQ== Return-Path: X-Original-To: python-de@python.org Delivered-To: python-de@mail.python.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=frz4CzrebV1dxLei7Dc5aCOMsDXKWqZGpT4eR9J6qj0=; b=rPxNaph+PXJNxtFU0LyI1j0E5SWWJ6b2zRyaauFunPRqTd3OPIjprNI7/a49DX+pFl S5dyULNhY2P8px931Pbj/qssFhDBfuGJXWKJ1dNMzlSGViElH2wMrWbf1a6PpRESfQ77 gBPW20FXxOWzP0KhOqQY+6rvqfuRR+vl4OPHLavVPtsWFci9mB4XDUO/jWGKkfk0tXJ4 cQP7g0UXonMbVTLcGPuwvMKrxZ/qfpWOqsglBYQ3zn+9fxI2tbJc8iw3ZfYldjEIA5yT z3fIsKI3DS2Z1EMdcHbFb6irVujKmAdZjFhcmEr4KfRJ8a3zAzdlDgnPAgMyeyFVPtNQ eceQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=frz4CzrebV1dxLei7Dc5aCOMsDXKWqZGpT4eR9J6qj0=; b=a72a24cX20rOad3MUDnmBnriw6y0SEUWII5WstaQgAgSwObc30Yoo4E5JbHh691jM3 uMctdtio/3ZRMkX9lSX/Cpw2h3iNxPGx1TSeu6DIYk7oofZe+CC9YTbGcYNvALMvp5uV 1L13tACNyW8l2648HEqVQeEkbJoROFn6wG0h3wkYYRcbwjIUaS2Ddl+fFlC8jXxQg62T NQqELH0go3oq38J1N9ye/1Ff2zPY0v5/HkEfNThUuGNBYhbjL9C0EIOTwkTyxsqTOpjH CejzX5OCL3I+zu0JPK9H1Z/0fy8B2gnOxrbXSsIJUhyNJPL9pOAuAcMfjx5Nckyfsn6u ey2w== X-Gm-Message-State: APzg51DGtUWtbkPv52wMJmq46a+dzCq4X0kikNEsCHYOCxhE8FpCwelP RMWnCgG22QA7Yh6m1agk0CmuNAt4xz05lkSao2w= X-Google-Smtp-Source: ACcGV63DIp/M1A/YPavzlsgs/K0O9EOxcVyCs+TLf666QTT+Ta87ftHP/gGYfkusItjaWoLY1Z8c7a+NNbXvqKxOKDc= X-Received: by 2002:a2e:870b:: with SMTP id m11-v6mr11033116lji.2.1537785993200; Mon, 24 Sep 2018 03:46:33 -0700 (PDT) In-Reply-To: <33920c93-417b-ef60-4f54-cdfb878ed21c@redcor.ch> X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: python-de@python.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Die Deutsche Python Mailingliste List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <33920c93-417b-ef60-4f54-cdfb878ed21c@redcor.ch> Xref: csiph.com de.comp.lang.python:5247 Das liegt wahrscheinlich daran, dass die home Variable mit bytes oder bytearray statt mit str gef=C3=BCllt ist. Bei Python 3 ist ja schlie=C3=9Flich str(b"foo") "b'foo'" statt "foo". robert schrieb am So., 23. Sep. 2018, 16:08: > Hoi z=C3=A4me, > > > ich bin dabei scripts von v2 auf v3 zu konvertieren. > > Jetzt habe ich ein Problem mit popen: > > ich konstruiere einen Popen-Aufruf wie folgt: > > > Zuerst suche ich wo der virtualenvwrapper installiert ist: > > cmd =3D['/bin/bash', '-c', 'echo $(which virtualenvwrapper.sh)'] > p =3Dsubprocess.Popen(cmd, stdout=3DPIPE) > virtualenvwrapper =3Dp.communicate()[0].strip() > Dann bastle ich einen bash Aufruf, in dem Virtualenvwrapper aktiv ist, > und nutze diesen um einen Eintrag beim Virtualenwrapper zu l=C3=B6schen. > Dieses Vorgehen ist n=C3=B6tig, weil sonst bash virtualenvwrapper nicht > kennt. Hier der Popen-Aufruf: > commands =3D""" > export WORKON_HOME=3D%(home)s/.virtualenvs\n > export PROJECT_HOME=3D/home/robert/Devel\n > source %(virtualenvwrapper)s\n > rmvirtualenv %(site_name)s > """%{ > 'home': os.path.expanduser("~"), > 'virtualenvwrapper': virtualenvwrapper, > 'site_name': site_name > } > p =3Dsubprocess.Popen( > '/bin/bash', stdin=3Dsubprocess.PIPE, stdout=3Dsubprocess.PIPE, shell=3DT= rue) > out, err =3Dp.communicate(commands.encode()) > Das funktionierte mit Python 2.7 gut. Der einzige unterschied war, dass > ich p.communicate(commands), anstelle von > p.communicate(commands.encode()) aufrufe. In Python 3 Bekomme ich > folgende Fehlermeldung: /bin/bash: line 6: > b/home/robert/.virtualenvs/workbench/bin/virtualenvwrapper.sh: No such > file or directory es scheint das b vor b/home/robert/.. zu sein, dass > den Fehler hervorruft. Wie muss ich vorgehen, um dieses Problem zu > vermeiden? Wenn ich dem Command string zuerst redigiere: > commands =3Dcommands.replace("b'/home", "'/home").encode() > funktionierts, aber das kann ja keine L=C3=B6sung sein. Danke Robert > _______________________________________________ > python-de maillist - python-de@python.org > https://mail.python.org/mailman/listinfo/python-de >