I have this function:
function checkfType(a,b){
exec("file '"+a+"'",function(err,stdout,stderr){
if(stdout.containsString(b)===true){return true}else{return false}
})
}
However, if I use it in an if statement like this:
if(checkfType(".","directory"){}
, it just goes "false".
I tested the exec
function as a non-function and using it instead of the if statement:
exec("file '.'",function(err,stdout,stderr){
if(stdout.containsString("directory")===true){
console.log("It works!);
}else{
console.log("It doesn't work.";}
});
Which works just fine.
I am led to believe tha the exec
function is async (or similar), which is where my problem lies.
Is there any way to use exec
's output in an if statement?