批处理文件,以检查另一个批处理是否已打开并在关闭时执行某些操作

时间:2019-05-27 21:39:56

标签: batch-file

我正在尝试获取我的其他程序可以调用的,以便当我的其他程序关闭时,它删除另一个程序创建的临时文件,该程序运行一个循环,所以我无法只需将其放在程序中的退出命令之前,因为它将永远无法到达它。

# timeframe : custom class that holds (among other things):
#    Frequency (pandas-compatible string representing periodicity)
#    Data (pandas dataframe where cols = close, open, high, low, volume, rsi; indexes = symbol, time)
#    Sarimax (dict that holds key (symbol) => value (dict of ARIMA order tuples)) generated by earlier script
# s : symbol name (ex., 'SPY')

forecasts = 25
def forecast_data(timeframe, series):
    data = series.asfreq(timeframe.Frequency)
    data.interpolate(inplace=True)
    # Limit datasize due to processing time (some models may fail due to too few nobs!)
    data = data.tail(1000)
    horizon = len(data) - forecasts
    return data[:horizon], data[horizon:]

# Datasets (training, testing, exog)
data = timeframe.Data.loc[s].close
training, testing = forecast_data(timeframe, data)

# Am I using exog correctly? I want to incorporate RSI into the predictive model
exog = timeframe.Data.loc[s].rsi
exog_training, exog_testing = forecast_data(timeframe, exog)

# Walk-Forward Forecasting
predictions = testing.copy(deep=True)
i = 1
print("{} SARIMAX {}x{} : {} rows".format(timeframe, timeframe.Sarimax[s]['order'], timeframe.Sarimax[s]['seasonal_order'], len(training)))
for index, value in testing.iteritems():
    print("   Forecasting {}/{} ({} @ {})".format(i, forecasts, '%.4f' % value, index), end='\r')
    # Fit Model
    fit = SARIMAX(training, order=timeframe.Sarimax[s]['order'], seasonal_order=timeframe.Sarimax[s]['seasonal_order'], enforce_stationarity=False, enforce_invertibility=False, exog=exog_training).fit()
    # one step forecast at current testing date from past training data
    # Am I using exog correctly here?
    predictions.loc[index] = fit.forecast(exog=pd.DataFrame(exog_training.tail(1))).iloc[0]
    # move testing data into training data for the next fit + forecast
    training.loc[index] = value
    exog_training[index] = exog_testing[index]
    i += 1
print('')

# Data/Fit Comparison
plt.figure(figsize=(16, 5))
plt.xlabel("Timeframe: {}".format(timeframe))
plt.ylabel("Price")
# Trim training plot for better visual inspection
training = training[-forecasts:]
plt.ylim(bottom=min(training), top=max(training))
training.plot(label=s + " Actuals", marker='o')
predictions.plot(label=s + " Predictions", marker='o')
plt.legend(loc='upper left')
ax = plt.gca()
ax.grid(which='major', alpha=0.5, linestyle='--')
ax.grid(which='minor', alpha=0.5, linestyle=':')
plt.show()
print(fit.summary())
fit.plot_diagnostics()
plt.show()

2 个答案:

答案 0 :(得分:1)

类似

@ECHO OFF
START "" /WAIT "C:\Program Files\Foo\OtherApplication.exe"
DEL "C:\Temp\Foo.tmp"

不起作用?

答案 1 :(得分:0)

对于无法使用Christoph的答案的人,解决方法非常慢。

@echo off

:loop
set "l=0"
for /f "delims=" %%i in ('tasklist /v') do (
    for /f %%j in ('echo %%i ^| find /c "process name"') do (
        set /a l+=%%j
        goto break
    )
)
:break
cls
if %l% gtr 0 (
    echo Process is still running...
) else (
    echo Process is not running
)
goto loop

您可以使用title更改批处理文件的进程名称,或仅搜索文件路径。