Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created October 7, 2019 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/925b055fb56f700f74e4d46b74551038 to your computer and use it in GitHub Desktop.
Save parzibyte/925b055fb56f700f74e4d46b74551038 to your computer and use it in GitHub Desktop.
func obtenerListaDeImpresorasCompartidasWindows() []string {
salida, err := exec.Command("cmd", "/C", "wmic", "printer", "get", "name").Output()
if err != nil {
log.Fatal(err)
}
salidaCadena := string(salida)
listaDeImpresoras := strings.Split(salidaCadena, "\r\r\n")
var listaDeImpresorasLimpias []string
for _, impresora := range listaDeImpresoras {
nombreLimpio := strings.TrimRight(impresora, " ")
if len(nombreLimpio) > 0 && nombreLimpio != "Name" {
listaDeImpresorasLimpias = append(listaDeImpresorasLimpias, nombreLimpio)
}
}
return listaDeImpresorasLimpias
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment