From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: Convert the shell command used in emacs init-file into its normal version. Date: Wed, 9 Jun 2021 10:13:09 +0200 Message-ID: <20210609081309.GE21706@tuxteam.de> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="19uQFt6ulqmgNgg1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29238"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/1.5.21 (2010-09-15) Cc: help-gnu-emacs To: Hongyi Zhao Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 09 10:14:12 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lqtLo-0007Ro-NM for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 09 Jun 2021 10:14:12 +0200 Original-Received: from localhost ([::1]:58856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqtLn-0005Nl-PA for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 09 Jun 2021 04:14:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqtKw-0005Lv-PH for help-gnu-emacs@gnu.org; Wed, 09 Jun 2021 04:13:18 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]:40040) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.90_1) (envelope-from ) id 1lqtKp-0007VE-R9 for help-gnu-emacs@gnu.org; Wed, 09 Jun 2021 04:13:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:Date; bh=+ocSqg58voVBO/t6OAeU/gBZ8jk/CDAJZNbZboMgwlY=; b=p0iIfxsQ3GZspAcns8Snh4PRUZLV5cWVIoTUEkGap5dTMd+A5UlKGBcsAxfXbTxQaFrS/J5LbIbFL5SyeMLeLrMRVN+9FNPRP+6AaFleO0FaVhgPdXR8p4LD3yHrqg3KkiJZ/MSj1a0bQp6gXlvecti/dgWm4LXNFIlfltIzh/J9VHTcgSieLRCT/zemDxQc5JEpVFLYrs1O/8IPnjNMDMhYhG4m2AVswUJGifdUTT1UB4XGi79ERYoP2X10xGupGsIq+TPIVVBBZmd6bv1ABMBVdFmcWnCcKP+vKRTKwfjK+hbVardoTyJUQavBka5iu55ezXSs5KMMe8O+mdIqnw==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1lqtKn-0007Zr-68; Wed, 09 Jun 2021 10:13:09 +0200 Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=5.199.139.25; envelope-from=tomas@tuxteam.de; helo=mail.tuxteam.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:130660 Archived-At: --19uQFt6ulqmgNgg1 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 09, 2021 at 04:03:09PM +0800, Hongyi Zhao wrote: > On Wed, Jun 9, 2021 at 3:01 PM Jean Louis wrote: > > > > * Hongyi Zhao [2021-06-09 09:50]: > > > I found the following command from > > > : > > > > > > "curl -s https://api.mathpix.com/v3/latex -X POST -H \"app_id: %s\" -H > > > \"app_key: %s\" -H \"Content-Type: application/json\" --data > > > \"{\\\"src\\\":\\\"%s\\\",\\\"formats\\\": > > > [\\\"latex_styled\\\"],\\\"format_options\\\":{\\\"latex_styled\\\": > > > {\\\"transforms\\\": [\\\"rm_spaces\\\"]}}}\"" > > > > > > I want to obtain its normal version and test it under the system's > > > shell terminal. Any hints for deleting the escape characters correctly > > > from the above command in Emacs way? > > > > You should use the function `call-process' as it will help with > > quoting: > > > > (call-process "curl" nil nil nil "-s" "https://api.mathpix.com/v3/latex" > > "-X" "POST" "-H" (format "app_id: %s" id) > > "-H" (format "app_key: %s" key) > > "-H" "Content-Type: application/json" > > "--data" "{\"src\":\"%s\", > > \"formats\": [\"latex_styled\"], > > \"format_options\": {\"latex_styled\": > > {\"transforms\": [\"rm_spa= ces\"]}}}") >=20 > You've stripped the escaping characters out manually in the above code. It's a bit more complex than that: The above is one big string in Emacs lisp which is to be passed to a shell. So it has an "outer" syntax, to be interpreted by the Emacs lisp reader, and an "inner" to be interpreted by the shell reader. The below is split into several strings (call-process takes a list of arguments, which are passed to exec), so no "shell escaping" is necessary. But since the individual arguments are represented as Emacs lisp strings, they need that escaping. So in a way yes, one layer of escaping has been removed, but it's the lower layer, the shell escaping. It just looks very similar to the upper (lisp) layer :-) Cheers - t --19uQFt6ulqmgNgg1 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAmDAeBUACgkQBcgs9XrR2kaaBgCffWWvoO6EQ7fuszcCkkm3v6C4 Z70Ani17HWt4rRpOhR9Sv01y3WQLI7Ba =g96h -----END PGP SIGNATURE----- --19uQFt6ulqmgNgg1--