完成fs.writeFilesync时回调

时间:2019-05-13 12:36:27

标签: javascript fs

我有这行代码来创建文件。我希望在文件创建后收到一条类似“文件创建成功”的消息。

fs.writeFileSync('reports/' +fileName+ '.pdf', resp.content);

1 个答案:

答案 0 :(得分:-1)

您使用的方法是同步方法。无需为此类曲调回调。如果要在操作完成后显示消息,只需在下一行控制台登录即可。

Msg 39004, Level 16, State 20, Line 2
A 'Python' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004.
Msg 39019, Level 16, State 2, Line 2
An external script error occurred: 

Error in execution.  Check the output for more information.
Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "C:\PROGRA~1\MICROS~3\MSSQL1~1.MPR\MSSQL\EXTENS~1\MPRYCESQLSEVER01\1D611E8A-CDE1-4F30-9FAC-0BB13871A3DE\sqlindb.py", line 59
    print(f"Houston, we have a problem {e}")
                                          ^
SyntaxError: invalid syntax

SqlSatelliteCall error: Error in execution.  Check the output for more information.
STDOUT message(s) from external script: 
SqlSatelliteCall function failed. Please see the console output for more information.
Traceback (most recent call last):
  File "C:\Program Files\Microsoft SQL Server\MSSQL14.MPRYCESQLSEVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\computecontext\RxInSqlServer.py", line 406, in rx_sql_satellite_call
    rx_native_call("SqlSatelliteCall", params)
  File "C:\Program Files\Microsoft SQL Server\MSSQL14.MPRYCESQLSEVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\RxSerializable.py", line 291, in rx_native_call
    ret = px_call(functionname, params)
RuntimeError: revoscalepy function failed.

如果要异步写入文件,请改用fs.writeFileSync('reports/' +fileName+ '.pdf', resp.content); console.log('write operation done');

fs.writeFile