<div dir="ltr" gmail_original="1">One option is to set env variables before launching the qgis command. The env variables can be read from python.<div><br></div><div>set QGIS_MESSAGE=Helllo World<br><div></div></div><div><br></div><div>Then your myscript.py can be something like</div><div><br></div><div>from qgis.utils import iface<br>import os<br><br>message = os.environ['QGIS_MESSAGE']<br>iface.messageBar().pushMessage(message)<br></div><div><br></div><div><br></div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">---<div>Ujaval Gandhi</div><div>Spatial Thoughts</div><div><a href="http://www.spatialthoughts.com" target="_blank">www.spatialthoughts.com</a></div><div><br></div></div></div></div><br></div><br><img width="0" height="0" class="mailtrack-img" alt="" style="display:flex" src="https://mailtrack.io/trace/mail/w/cWdpcy11c2VyQGxpc3RzLm9zZ2VvLm9yZw==/378d783efdc52797b2f67d6259daaf13bc77c776.png?u=8747767" ><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Aug 8, 2022 at 7:52 PM Matthias Kuhn via QGIS-Developer <qgis-developer@lists.osgeo.org> wrote:<br></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div dir="ltr">Hi Peter,<div><br></div><div>You are correct with the analysis of the situation.</div><div><br></div><div>Even if `qgis --help` states the following:</div><div> [--]          treat all following arguments as FILEs<br></div><br><div>it does in fact already interpret parameters as files before the `--` parameter.</div><div>Changing this behavior is risky (it will break many startup scripts out there) and can be considered for QGIS 4.</div><div>For now, we could add another marker as a band aid, e.g. we add a `--ex` (extra-parameters) that indicates that any parameters that follow should NOT be interpreted as files:<br></div><div><br></div><div>    qgis -p 1234.qgs --code script.py [files could be here] --ex --myparam=1324 -- [more files can still be here]</div><div><br></div><div>If that sounds like what you are looking for, we are happy to help you with that</div><div><br></div><div>Best regards</div><div>Matthias</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Aug 8, 2022 at 3:55 PM Drexel Peter via QGIS-Developer <<a href="mailto:qgis-developer@lists.osgeo.org" target="_blank">qgis-developer@lists.osgeo.<wbr>org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">





<div lang="DE-AT">
<div>
<p class="MsoNormal"><span lang="EN-US">Hi everyone,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">My goal: I want to open QGIS using the Command-Line, load a specific project, select specific features and zoom to the selected features.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">What sounds rather difficult is actually mostly solvable using the following:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">"C:\Program Files\QGIS 3.16\bin\qgis-ltr-bin.exe" -p "d:\standardebenen.qgs" --code myscript.py<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">This opens QGIS with the Project d:\standardebenen.qgs and after that it runs the script “myscript.py”.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Within the scrip I can do everything what I can do in a Python-script, so there I can select some features in a layer and show that selection.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">But this selections are “hard-coded” in the script, I cannot pass over these parameters to the myscript.py.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">In “Pure Python” I can pass parameters to a Python Script using “python myscript.py arg1 arg2 arg3”.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">This seems to be not working in the QGIS-Command-Line  as the parameters are interpreted as “layers to load”.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Am I right with my analysis?<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">One workaround is to write the parameters to al file and use this file within the myscript.py to define the selections. But this is very unhandy…<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Are there any ideas from any QGIS-Expert to solve my problem?<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">If this cannot be solved in the current version of QGIS is one of the developers willing to get in contact with me to make an offer the implement this feature ?
<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Thanks<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Peter<u></u><u></u></span></p>
</div>
</div>

______________________________<wbr>_________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a><br>
</blockquote></div>

<br>
<div style="text-align: left;"><a href="https://qfield.org/get/" target="_blank"><img src="https://ci4.googleusercontent.com/proxy/GqvhkBbIsDNWtqe2HThZLEElIli5211Hog29CYort7mWquajzTRIucqyquJ4nK_KuFTbuEa2CCNNIfLx52nBCCQkb6EWyBAfIjM_iV06dJPuBZpmAolhpdzysf0=s0-d-e1-ft#https://www.opengis.ch/wp-content/uploads/2022/04/Qfield_Banner_email.png" alt="https://qfield.org/get/"></a><span style="font-family: Arial;"><a><br></a></span></div><div style="text-align: left;"><span style="font-family: Arial;">QFIELD 2.0 IS HERE!<span style="font-family: Roboto, RobotoDraft, Helvetica, Arial, sans-serif;"><font size="3"> </font></span>- Hold the power of QGIS in your hand</span><span style="font-family: Arial;"> - <a href="https://www.opengis.ch/2022/04/05/qfield-2-0-is-here/" target="_blank">learn more</a> - <a href="https://qfield.org/get" target="_blank">get it now</a><br></span></div>______________________________<wbr>_________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailma<wbr>n/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailma<wbr>n/listinfo/qgis-developer</a><br>
</blockquote></div>