我在这段代码中有问题
public void setTmbhUserFtp(View v) {
Spinner spinner = (Spinner) findViewById(R.id.spinner);
Server server = serverlist.get(spinner.getSelectedItemPosition() - 1);
EditText EditAdduser = (EditText) findViewById(R.id.EditAdduser);
EditText EditPassworduser = (EditText) findViewById(R.id.EditPassworduser);
String sTextAdduser = EditAdduser.getText().toString();
String sTextPassworduser = EditPassworduser.getText().toString();
if (server != null && sTextAdduser.length() > 0
&& sTextPassworduser.length() > 0) {
final String ADDUSER = "sh /home/add_user.sh".concat(sTextAdduser) .concat(sTextPassworduser);
FtpConnect u = new FtpConnect();
Command o = new Command(getResources().getText(R.string.adduser)
.toString(), ADDUSER, server);
u.setCommand(ADDUSER);
pd = ProgressDialog.show(actual,
getResources().getString(R.string.PleaseWait), o.getName());
actualThreadCommand = o;
Thread thread = new Thread(actual);
thread.start();
} else {
Toast.makeText(getBaseContext(),
getResources().getText(R.string.gagal), Toast.LENGTH_LONG)
.show();
}
}
该代码用于像这样在linux中执行
sh /home/add_user.sh username password
但是当我从我的 android 尝试时,用户名和密码是一个
所以代码是这样的
sh /home/add_user.sh usernamepassword
如果用户名是 irfan,密码是 irfan,则检测代码
sh /home/add_user.sh irfanirfan
所以用户名是 irfanirfan 并且没有密码
代码 add_user.sh 是
useradd $1; echo -e "$2\n$2" | passwd $1
如何解决
final String ADDUSER = "sh /home/add_user.sh ".concat(sTextAdduser) .concat(sTextPassworduser);
.concat(sTextAdduser) 之后必须是空格
所以在linux中会执行
sh /home/add_user.sh irfan irfan