我正在尝试通过JSch运行命令。我可以运行诸如public class PieView : View
{
int w, h, pl, pr, pt, pb, usableWidth, usableHeight, radius, cx, cy, lineLenght;
Paint paint;
public Canvas canvas;
public float prevFirstLineAngle = 0;
public float prevSecondLineAngle = 0;
public float prevThirdLineAngle = 0;
public float firstLineAngle = 0;
public float secondLineAngle = 40;
public float thirdLineAngle = 120;
float currentAngle, maxAngle;
public override void Draw(Canvas canvas)
{
base.Draw(canvas);
w = Width;
h = Height;
pl = PaddingLeft;
pr = PaddingRight;
pt = PaddingTop;
pb = PaddingBottom;
this.canvas = canvas;
usableWidth = w - (pl + pr);
usableHeight = h - (pt + pb);
radius = Math.Min(usableWidth, usableHeight) / 2;
cx = pl + (usableWidth / 2);
cy = pt + (usableHeight / 2);
lineLenght = radius - (pl * 2) - (pr * 2);
paint = new Paint();
paint.Color = Android.Graphics.Color.White;
paint.SetStyle(Paint.Style.Stroke);
paint.StrokeWidth = 5;
canvas.DrawCircle(cx, cy, radius - 5, paint);
Drawline(canvas, firstLineAngle);
Drawline(canvas, secondLineAngle);
Drawline(canvas, thirdLineAngle);
PostInvalidateDelayed(500);
Invalidate();
}
public void SaveCurrentAngles()
{
prevFirstLineAngle = this.firstLineAngle;
prevSecondLineAngle = this.secondLineAngle;
prevThirdLineAngle = this.thirdLineAngle;
}
public void Drawline(Canvas canvas, float angle)
{
float displacedAngle = angle - 90;
float x = cx + ((float)Math.Cos(degreesToRadians(displacedAngle)) * (radius - 5)); //convert angle to radians for x and y coordinates
float y = cy + ((float)Math.Sin(degreesToRadians(displacedAngle)) * (radius - 5));
canvas.DrawLine(cx, cy, x, y, paint); //draw a line from center point back to the point
}
public double degreesToRadians(double degrees)
{
return (degrees * Math.PI) / 180;
}
}
public class PieAnimation : Android.Views.Animations.Animation
{
private PieView pieView;
private float firstLineAngle;
private float secondLineAngle;
private float thirdLineAngle;
public PieAnimation(PieView pieView, float firstLineAngle, float secondLineAngle, float thirdLineAngle)
{
this.pieView = pieView;
pieView.saveCurrentAngles();
this.firstLineAngle = firstLineAngle;
this.secondLineAngle = secondLineAngle;
this.thirdLineAngle = thirdLineAngle;
}
protected override void ApplyTransformation(float interpolatedTime, Transformation t)
{
pieView.firstLineAngle = pieView.prevFirstLineAngle +
((firstLineangle - pieView.prevFirstLineAngle) * interpolatedTime);
pieView.secondLineAngle = pieView.prevSecondLineAngle +
((secondLineangle - pieView.prevSecondLineAngle) * interpolatedTime);
pieView.thirdLineAngle = pieView.prevThirdLineAngle +
((thirdLineangle - pieView.prevThirdLineAngle) * interpolatedTime);
pieView.RequestLayout();
}
}
public class TourPager : Java.Lang.Object, ViewPager.IOnPageChangeListener, ViewPager.IPageTransformer
{
private ViewPager mViewPager;
private float mLastOffset;
public TourView _context;
public TourPager(ViewPager viewpager, TourView context)
{
mViewPager = viewpager;
viewpager.AddOnPageChangeListener(this);
_context = context;
}
public void OnPageSelected(int position)
{
if (position == 0)
{
PieAnimation animation = new PieAnimation(_context._pieView, 0, 40, 120);
animation.Duration = (1000);
_context._pieView.StartAnimation(animation);
}
if (position==1)
{
PieAnimation animation = new PieAnimation(_context._pieView, 100, 140, 200);
animation.Duration=(1000);
_context._pieView.StartAnimation(animation);
}
if(position==2)
{
PieAnimation animation = new PieAnimation(_context._pieView, 180, 270, 10);
animation.Duration = (1000);
_context._pieView.StartAnimation(animation);
}
}
}
之类的标准命令。但是,如果我需要运行命令,假设ls
会重新运行
ksh:abc:找不到
我尝试使用abc <param>
,但仍然无法使用。
我的频道设置如下:
((ChannelExec)channel).setPty(true);
如何使我的自定义命令和别名与JSch一起使用?
答案 0 :(得分:2)
最简单的方法是制作自定义的“命令”脚本,而不是别名(或函数)。脚本可用于所有外壳模式,所有外壳以及find xargs nohup nice
之类的非外壳程序。
如果必须具有别名,并且给定使用的是pty,则它应该可以以交互方式显式运行ksh
。对于您所显示的(非常)简单的命令,您可以仅使用"ksh -i -c abc"
作为命令,并确保别名位于~/.kshrc
中。 (ksh
允许使用envvar ENV将nonlogin rc放在其他位置,但是出于安全性的考虑,通常禁止或限制通过ssh传递envvars。)但是,如果您需要带有参数的更复杂的命令,尤其是(如果需要)包含空格或特殊字符(如引号,美元,反引号或反斜杠),弄清楚导致-c
执行正确命令的ksh
自变量可能会变得非常困难,特别是如果您还需要在Java源代码中将它表示为字符串文字(即,不是从文件或数据库或envvar等中)。