実行時にGUIボタンをユーザーに表示し、それを押すとJavaコードがあります。bash スクリプトが実行されます。私のスクリプトは端末で動作しますが、Runtime.getRuntime().exec を介して Java でスクリプトを実行しようとすると、権限エラーが発生します。コマンドで chmod 777 も使用しましたが、すべて無駄でした。
**MY Java code is**
package com.interface_saad;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.io.File;
/**
*
* @author Saad
*/
public class Main {
/**
* @param args the command line arguments
*/
static JFrame fr=new JFrame("QoS");
static JPanel button_pan=new JPanel();
static JButton QoSButton=new JButton("QoS");
public static void main(String[] args) throws IOException {
final File file = null;
button_pan.add(QoSButton);
fr.add(button_pan,BorderLayout.CENTER);
fr.setVisible(true);
fr.setSize(200,200);
QoSButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
System.out.println("path");
Runtime.getRuntime().exec("chmod 777 /home/talal/enable.sh");
Runtime.getRuntime().exec("./ /home/talal/enable.sh");
} catch (Exception ex) {
System.out.println(ex);
}
}
});
fr.setDefaultCloseOperation(fr.EXIT_ON_CLOSE);
}
}
私のbashスクリプトはenable.shです
#!/bin/sh
(sleep 2
echo root
sleep 2
echo admin
sleep 1
echo '/usr/sbin/svqos status `get_wanface` 0'
sleep 2
echo '/usr/sbin/svqos `nvram get wshaper_downlink` `nvram get wshaper_uplink` `get_wanface` `nvram get wan_mtu` 0 '
sleep 1
echo '/usr/sbin/svqos status `get_wanface` 0'
sleep 4) | telnet 192.168.1.1 -l root
提案が必要です。私は切実に助けが必要です。