Chrome扩展程序 - 消息传递到批处理文件 [英] Chrome Extension - Message Passing to batch file

查看:297
本文介绍了Chrome扩展程序 - 消息传递到批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了示例项目
https://developer.chrome.com/extensions/samples
我能够运行python原生应用程序。



是否有任何方式在native-messaging-example-host中获取消息。蝙蝠



我不想加载python脚本



我想在这里做的是
从chrome发送消息{text:xyz.bat}



并且批处理文件应该运行START xyz.bat

> 不应从批处理文件的角度来看这个问题,因为代替我的解决方案,它需要程序先行运行,在大多数应用程序中折旧有利于在后台运行它。 然而,如果你仍然想知道你怎么可能批量做到这一点...



如果你可以将消息传递给一个空白html页面(当前不确定如何或想要这样做),其中该页面上的唯一内容是您的 runme.bat ,我们可以运行一个程序,复制页面,打开文本文件并粘贴到里面,关闭文本文件,然后运行带有输入的批处理文件。因此,明智的代码,

  @if(@CodeSection == @Batch)@then 
@echo off
set SendKeys = CScript // nologo // E:JScript%〜F0

rem下面复制页面上的所有内容,并关闭它
%SendKeys%{TAB}
%SendKeys%^ {A}
SendKeys%^ {C}
%SendKeys%^ {W}

rem打开文本文件,等待它加载,粘贴剪贴板,保存并退出

开始newreadforme.txt
超时/ nobreak / t 5
%SendKeys%^ {V}
$ SendKeys%^ {S}
timeout / nobreak / t 2
%SendKeys%^ {W}
start program.bat
goto:EOF
@end
// JScript部分
var WshShell = WScript.CreateObject(WScript.Shell);
WshShell.SendKeys(WScript.Arguments(0));

然后在您的批处理文件中

  @echo off 
set /px=<newreadforme.txt
start%x%

此代码将在打开的页面上运行模拟击键,以复制其内容并将其转发到要从另一批处理文件引用的文本文件。 但您应该只使用这种方法作为最后的手段,因为这种方法是解决您的问题的一种可怕方式。我的代码要求您保持网页的开放性和前瞻性,并确保没有人干涉该程序在执行期间。因此,如果用户在使用计算机时运行,那么他们可能会意外地混淆输入。



最重要的是,您已经需要将网页修改为实现你的最终结果,所以你可能应该使用支持html文件系统操作的语言。 Nodejs可以在文件系统和html页面之间提供一个很好的界面,你可以决定通过。如何处理填充了我不确定的消息的网页,但是您绝对应该避免使用批处理来执行您要求的更多HTML友好语言

I used the sample project https://developer.chrome.com/extensions/samples I am able to run the python native app.

Is there any way to get the message within native-messaging-example-host.bat

I don't want to load python script

What I want to do here is send message from chrome {text: "xyz.bat"}

and the batch file should run START xyz.bat

解决方案

You should not approach this problem from the batch file standpoint, as in lieu of my solution, it requires the program to be run upfront, which in most applications is depreciated in favor of running it in the background. However if you still want to know how you could potentially do it in batch...

If you can pass the message to a blank html page (not currently sure how you can or want to do it this way), where the only thing on that html page is your runme.bat we can run a program that would copy the page, open a text file and paste it inside, close the text file, and run the batch with input from it. So code wise,

@if (@CodeSection == @Batch) @then
@echo off
set SendKeys=CScript //nologo //E:JScript "%~F0"

rem below copys everything on the page, and closes it
%SendKeys% "{TAB}" 
%SendKeys% "^{A}"
%SendKeys% "^{C}"
%SendKeys% "^{W}"

rem open text file,wait for it load, paste clipboard, save and exit

start newreadforme.txt
timeout /nobreak /t 5 
%SendKeys% "^{V}"
%SendKeys% "^{S}"
timeout /nobreak /t 2
%SendKeys% "^{W}"
start program.bat 
goto :EOF
@end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));

then in your batch file

@echo off
set /p x=<newreadforme.txt
start %x%

This code will run simulated keystrokes on the opened page to copy its contents and relay to a text file to be referenced from another batchfile. But you should only use this method as a last resort as this approach is a TERRIBLE way to solve your problem. My code requires you to keep the webpages open and upfront and make sure no one interferes with the program during its execution. So if a user is using the computer the time its running, then they may accidentally mess with the inputs.

On top of that, already you need to be modifying webpages to achieve your end result so you probably should use a language that supports html to filesystem operations. Nodejs can provide a nice interface between the file system and html pages that you may decide to pass. How you handle the webpage filled with the message i am not sure of but you should most certainly avoid using batch to do what you ask in favor of more html friendly languages

这篇关于Chrome扩展程序 - 消息传递到批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆