Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

763
Visualizações
URL Encode in Windows Batch Script

I have a Windows batch script that I use to do quick Google searches. However, I can't figure out how to generically encode special characters. Like if I try to search for C#, the pound sign breaks it. Here is my code:

SET q="https://www.google.com/#q=%*"
SET q=%q: =+%
chrm %q%
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Without installing any external tools:

@echo off
setlocal


set "string=gibberish+?blahblah@"


:: Define simple macros to support JavaScript within batch
set "beginJS=mshta "javascript:code(close(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write("
set "endJS=)));""



:: FOR /F does not need pipe
for /f %%N in (
  '%beginJS% encodeURIComponent("%string%") %endJS%'
) do set encoded=%%N
echo %string% -^> %encoded%
over 4 years ago · Santiago Trujillo Relatório

0

I don't think there is a good way to do that directly in a Windows bat script. Python is a great solution for some heavier things like that, and it is cross platform which is always nice. Since you are in Windows, you could probably write a powershell script to do it. However, here is a Python 3 script I wrote which I think does what you are looking for.

import sys
import subprocess
import urllib.parse

browser = sys.argv[1]
browserParms = sys.argv[2]

queryString = " ".join(sys.argv[3:])
queryString = urllib.parse.quote(queryString)
url = "https://www.google.com/#q=" + queryString

subprocess.Popen([browser, browserParms, url])

sys.exit()

Here is a native script for Linux where you can set up your specifics. You could do something very similar in a windows batch file. I named it goog (with no extension because that would be too much to type :) )

#!/bin/bash
python3 /home/justin/Dropbox/MyFiles/Programs/CrossPlatform/Python3/GoogleSearch.py "firefox" "-new-window" "$@"

Make sure your native script location is in $PATH. Execute like this from Terminal or Run A Command.

goog i like turtles
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda