Node.js Exec:进程无法访问该文件,因为其他进程正在使用该文件
如果user2在exec处理时发出get请求,则向user1提供的数据错误 我有以下函数,它从输入文件中定义的SQL查询生成输出文本文件Node.js Exec:进程无法访问该文件,因为其他进程正在使用该文件,node.js,Node.js,如果user2在exec处理时发出get请求,则向user1提供的数据错误 我有以下函数,它从输入文件中定义的SQL查询生成输出文本文件 function createQueryFile(callback){ var exec = require('child_process').exec; var child = exec("C:\\SQL < txt/inp.txt > txt/out.txt",function( error, stdout, stderr) {
function createQueryFile(callback){
var exec = require('child_process').exec;
var child = exec("C:\\SQL < txt/inp.txt > txt/out.txt",function( error, stdout, stderr)
{
if ( error != null ) {
console.log("error);
} else{
callback();
}
});
}
当两个用户几乎同时打开网站时,控制台会说:
进程无法访问该文件,因为其他进程正在使用该文件。
我相信exec抱怨其中一个文件被锁定
因此,错误的数据被提供给用户,而用户打开网页的速度快了几毫秒。假设u1打开网页,us2在20毫秒后打开,然后u2数据显示给u1和u2
当它们不同时打开时,一切都很好
有没有提示如何解决?多谢各位 每次生成子进程时,您能使用不同的文件名吗?是的,我想到了,但希望使用更优雅的解决方案,无论如何,thx提示PeterCunness您使整个事务同步,违反了prime指令,我不知道如何解决它。明白了,谢谢。
app.get("/",function(req,res){
createQueryFile((err,data)=>{
if (err){
console.log("something went wrong in get file");
}else {
findData((err,data)=>{
if (err){
console.log("something went wrong with analyze file")
}else{
res.render("welcome",{data:data});
}
});
}
});