Chrome本地消息传递无法执行批处理文件 [英] Chrome native messaging cannot execute batch file

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

问题描述

以下是我的主机清单:

  {
allowed_origins:
[
chrome-extension:// EXTENSION_ID /

description:my.app.host,
name:my.app.host ,
路径:C:\\\\\\\\\\\\\\\\\\\'','
type:stdio
}

以下是我的launch.bat文件的内容:

  setlocal enableextensions disabledelayedexpansion 

for %% a in(%〜dp0\ChromeConnector.jar)do setJARFILE = %%〜fa
java -jar%JARFILE%
暂停




  • 当我
  • 当我使用EXE文件(用C#开发)从我的网站启动扩展程序时,它可以正常工作。

  • 但是当我使用BAT文件从我的网站启动我的扩展程序时,它似乎不起作用。


    1. 我只能测试BAT的一部分吗? (把BAT的回显文本放在我的应用程序中查看结果?)


    2. 我尝试使用以下行来启用在chrome中的日志记录:启动chrome --enable-logging --v = 1 但是没有在 AppData \Local\Google\Chrome\User Data中找到特定日志\chrome_debug.log ,我是否需要添加一些内容来记录特定的错误?

    3. 我的Java代码就像这样简单目前为止:

    public static void main(String [] args){
    while(true){}
    }




方式来测试jar应用程序?



提前致谢

解决方案

以下是您的问题的一些答案:

1。我可以只测试BAT的一部分吗? (把英美烟草公司的回应文本放在我的应用程序中查看结果?)



在您的BAT中,您可以将Java程序的输出发送到一个文本文件。如果该文件在尝试通话后存在,则表示该扩展程序能够启动本机应用程序,并且您将能够看到应用程序输出。例如,在BAT的第四行中,您可以执行此操作:

  java -jar%JARFILE%>> ; mybatfile.log 

2。我尝试使用以下命令启用chrome日志记录:启动chrome --enable-logging --v = 1,但AppData中的所有日志似乎都没有找到。\ Local \\\\\\\\\\\\\\\\\\\\\\\\\\\\\日志,我是否需要添加一些内容来记录特定的错误?



查找包括native_message_process_host.cc的邮件,例如:

  [4680:5612:0809/194917:错误:native_message_process_host.cc(291)]本机消息传递主机尝试发送长度为2036688930个字节的消息。 

3。我的Java代码现在简单如此:

  public static void main(String [] args) {
while(true){}
}

请参阅这篇文章从java接收和发送stdio消息:
Java扩展的本地消息传递 - 无法正确写入长度



4。是否有另一种方法来测试jar应用程序?



我建议从您的java应用程序生成日志,以便查看收到和发送的消息,包括最初的4个字节表示消息的长度。

Here is the manifest of my host :

{
   "allowed_origins" : 
    [ 
        "chrome-extension://EXTENSION_ID/"
    ],
   "description" : "my.app.host",
   "name" : "my.app.host",
   "path" : "‪C:\\chromejar\\launch.bat",
   "type" : "stdio"
}

Here is the content of my launch.bat file :

setlocal enableextensions disabledelayedexpansion

for %%a in ("%~dp0\ChromeConnector.jar") do set "JARFILE=%%~fa"
    java -jar "%JARFILE%"
pause

  • When I launch my Batch file separately, it works.
  • When I launch my extension from my website using an EXE file (developed in c#), it works.
  • But when I launch my extension from my website using the BAT file, it does not seem to work.

    1. Can I test only the BAT part of it ? (put an echo text from the BAT to see the result on my app ?)

    2. I tried to enable logging in chrome using this line : start chrome --enable-logging --v=1 but no particular log seems to be found in AppData\Local\Google\Chrome\User Data\chrome_debug.log, Do I need to add something to log particular errors ?

    3. My Java code is as simple as this for the moment :

    public static void main(String[] args) { while(true) { } }

Is there another way to test the jar application ?

Thanks in advance

解决方案

Here are some answers to your questions:

1. Can I test only the BAT part of it ? (put an echo text from the BAT to see the result on my app ?)

In your BAT, you can send the output of your Java program to a text file. If the file exists after trying the call, it means the extension was able to launch the native app and you will be able to see the app output. For example, in the fourth line of your BAT you can do this:

java -jar "%JARFILE%" >> mybatfile.log

2. I tried to enable logging in chrome using this line : start chrome --enable-logging --v=1 but no particular log seems to be found in AppData\Local\Google\Chrome\User Data\chrome_debug.log, Do I need to add something to log particular errors ?

Look for messages including "native_message_process_host.cc", for example:

[4680:5612:0809/194917:ERROR:native_message_process_host.cc(291)] Native Messaging host tried sending a message that is 2036688930 bytes long.

3. My Java code is as simple as this for the moment :

public static void main(String[] args) {
    while(true) { }
}

Refer to this post for receiving and sending stdio messages from java: Java native messaging with chrome extension - cannot correctly write length

4. Is there another way to test the jar application ?

I suggest to generate logs from your java app, so you can review the received and sent messages, including the initial 4 bytes denoting the messages length.

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

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