我在进程上使用waitFor命令时遇到了问题。我的代码是这样的waitFor命令不等待
//preconditions
try{
// lock the work station
Process p= Runtime.getRuntime().exec("C:\\Windows\\System32\\rundll32.exe user32.dll,LockWorkStation");
int exitval=p.waitFor();
// If the authentication is successful
if(exitval==0)
{
//statements to insert into database
}
}
catch(IOException e)
{
e.printStackTrace();
}
catch (InterruptedException e) {
e.printStackTrace();
}
过程被锁定画面精细,但它在退出之前,用户实际上是能够与“0”的退出值验证和程序插入语句到我的数据库。我希望进程等待用户成功通过身份验证,然后将我的数据插入数据库。我已经搜索了很多,但没有取得任何成功。我应该使用不同的过程来锁定屏幕吗?
您是否尝试在命令行中添加'/ wait'参数? – Maroun
如果只检查一次! –
@PhilippSander这有什么问题? 'waitFor()'应该等待进程完成。 – Maroun