简体   繁体   English

从Java运行Shell脚本以通过USB发送数据

[英]Run shell script from Java to send data via USB

Exactly as specified in the title, I'm trying to send data to my ODROID-Show external screen via USB. 正是按照标题中的指定,我正在尝试通过USB将数据发送到ODROID-Show外部屏幕。 I'm running a shell script that sends such data. 我正在运行发送此类数据的shell脚本。 The problem is I can simply run the command through Terminal and it runs successfully and data is sent to my little screen through USB port. 问题是我可以简单地通过终端运行命令,该命令成功运行,并且数据通过USB端口发送到我的小屏幕。 When I try to run the same command via Java, Nothing happens. 当我尝试通过Java运行相同的命令时,没有任何反应。

Process proc = Runtime.getRuntime().exec("/bin/bash -c /home/ahmed/ODROID-SHOW-master/example/linux/images.sh /");

The specified command should have root privileges to run. 指定的命令应具有root特权才能运行。 That, I've switched to root then ran the code and nothing happened. 那,我已经切换到root用户,然后运行了代码,什么也没发生。 Any thoughts how to solve such problem? 有什么想法如何解决这样的问题?

Edit: 编辑:

IF you can show a code that executes given command prefixed by sudo this will absolutely work. 如果您可以显示一个执行给定命令(以sudo开头)的代码,则此命令绝对有效。

I was able to run the program as root. 我能够以root身份运行该程序。 but, corrupted data are sent to ODROIDscreen rather than valid images. 但是,损坏的数据将发送到ODROIDscreen,而不是有效的图像。 while it transfers successfully when ran through Terminal, Any thoughts why that happens? 当它通过终端运行时成功传输时,有什么想法会发生这种情况吗?

I would check if the script executed by the bash interpreter requires certain environment variables set before execution. 我将检查bash解释器执行的脚本是否需要在执行之前设置某些环境变量。

I'd add a debug line in the executed shell script to dump the environment like "env > my_dump_env.txt" then run the script both from command line as well as from Java and do a diff see what is missing or is different. 我将在已执行的Shell脚本中添加一条调试行,以转储“ env> my_dump_env.txt”之类的环境,然后从命令行以及从Java运行该脚本,并进行比较以查看缺少的内容或不同之处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM